public IActionResult UpdatePassWord(LoginModel login) { login.SuccessCode = 200; RSAKit rSAKit = new RSAKit(); Users user = _userRepository.GetUser(new Users { UniqueId = User.FindFirstValue(ClaimTypes.NameIdentifier) }); if (user == null || string.IsNullOrEmpty(user.Name_Cn)) { login.SuccessCode = 500; login.Msg = "登录状态失效,请退出重新登录!"; } if (login.SuccessCode == 200) { // Dick 2021-04-30 [ 验证历史密码是否正确 ] user.Password = rSAKit.RSADecrypt(user.PrivateKey, user.Password); if (!user.Password.Equals(login.OldPassWord)) { login.SuccessCode = 500; login.Msg = "密码错误,操作失败!"; } } if (login.SuccessCode == 200) { // Dick 2021-04-30 [ 验证两次密码输入是否一致 ] if (!login.PassWord.Equals(login.VerifyPassword)) { login.SuccessCode = 500; login.Msg = "两次密码输入不一致,操作失败!"; } } if (login.SuccessCode == 200) { // Dick 2021-04-30 [ 加密密码,Save ] string xmlPrivateKey, xmlPublicKey; rSAKit.RSAKey(out xmlPrivateKey, out xmlPublicKey); string pwd = rSAKit.RSAEncrypt(xmlPublicKey, login.PassWord); user.Password = pwd; user.PrivateKey = xmlPrivateKey; user.UpdateTime = DateTime.Now; user.UpdateName = User.Identity.Name; _userRepository.UpdatePassWord(user); } ViewBag.HttpContext = HttpContext; return(View(login)); }
public IActionResult Save(Users user) { user.UpdateTime = DateTime.Now; user.UpdateName = UserName; if (string.IsNullOrEmpty(user.UniqueId)) { string xmlPrivateKey, xmlPublicKey; RSAKit rSAKit = new RSAKit(); rSAKit.RSAKey(out xmlPrivateKey, out xmlPublicKey); string pwd = rSAKit.RSAEncrypt(xmlPublicKey, user.Password); user.Password = pwd; user.PrivateKey = xmlPrivateKey; user.CreateTime = DateTime.Now; user.CreateName = UserName; } bool isSave = _userRepository.Save(user); if (isSave) { user.SuccessCode = 200; } return(View(user)); }