0

I searched several places for how to change a user's password elegantly.

The one I came closest to using was the one in this post: ASP.NET Identity reset password

My algorithm:

ApplicationUser user = await _userManager.FindByIdAsync(model.Id);  

user.UserName = model.Name;
user.Email = model.Email; 
 
if(model.ChangePassword != null)
{
    var newPasswordHash = _userManager.PasswordHasher.HashPassword(user, model.ChangePassword);
    user.PasswordHash = newPasswordHash;
}

identityResult = await _userManager.UpdateAsync(user);

But this way the administrator, when filling this field, will not have the validity of IdentityOptions.

Connor Low
  • 5,900
  • 3
  • 31
  • 52

1 Answers1

0

Following should be a comment but I cannot comment, try using UserManager.GeneratePasswordResetTokenAsync and UserManager.ResetPasswordAsync or inherit from UserManager and you will have access to protected method UpdatePasswordHash(TUser user, string newPassword, bool validatePassword) (source code) which you can expose with your own API.

41D0
  • 161
  • 5