Search code examples
asp.net-identitypassword-hash

Get copy of password hash when changing password via ASP.NET Identity


I have a requirement to prevent users from re-using passwords they have already used in the past. To that end I want to record the hashed version of their password in a separate table so that I can compare any future password changes against the values in the table.

I currently use the following Identity method to change the password.

IdentityResult result = await this.AppUserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

This changes the password and stores it as a hash in the AspNetUsers table however is there a way I can return that hash so I can store it myself?


Solution

  • Take a look at Section 3 of this article from Microsoft on how to do exactly what you are trying to do. I implemented this pattern and it works great.

    Implementing custom password policy using ASP.NET Identity

    Here is another article to get you going:

    How To Customize Password Policy in ASP.Net Identity