public bool ResetPassword(string userName, string newPassword) { String hashedNewPassword = _userMng.PasswordHasher.HashPassword(newPassword); var hashResult = _userMng.PasswordHasher.VerifyHashedPassword(hashedNewPassword, newPassword); IdentityUser cUser = _userMng.FindByName(userName); UserStore <IdentityUser> store = new UserStore <IdentityUser>(); cUser.PasswordHash = hashedNewPassword; _userMng.Update(cUser); // password change compleled update last password change BLL.AccountMng accBll = new BLL.AccountMng(); accBll.UpdateLastPasswordChange(cUser.Id); return(true); }
public bool ChangePassword(string userName, string newPassword, string oldPassword, out string errMsg) { errMsg = string.Empty; try { if (newPassword == oldPassword) { throw new Exception("New password can not be the same as old password!"); } IdentityUser cUser = _userMng.FindByName(userName); IdentityResult result = _userMng.ChangePassword(cUser.Id, oldPassword, newPassword); if (result.Errors.Count() > 0) { foreach (string msg in result.Errors) { if (!string.IsNullOrEmpty(errMsg)) { errMsg += Environment.NewLine + msg; } else { errMsg += msg; } } throw new Exception(errMsg); } // password change compleled update last password change BLL.AccountMng accBll = new BLL.AccountMng(); accBll.UpdateLastPasswordChange(cUser.Id); } catch { return(false); } return(true); }