ASP.NET Identity 2.0: How to rehash password

后端 未结 2 1718
深忆病人
深忆病人 2021-01-05 05:04

I am migrating users from a legacy user store to ASP.NET Identity 2.0 in my ASP.NET 5.0 web application. I have a means of verifying legacy hashes, but I want to upgrade the

2条回答
  •  有刺的猬
    2021-01-05 05:15

    It seems rehashing mechanism is not implemented in the built-in user manager. But hopefully you could easily implemented. consider this:

    public class ApplicationUserManager : UserManager
    {
        protected override async Task VerifyPasswordAsync(
              IUserPasswordStore store, 
              ApplicationUser user, string password)
        {
            var hash = await store.GetPasswordHashAsync(user);
            var verifyRes = PasswordHasher.VerifyHashedPassword(hash, password);
    
            if (verifyRes == PasswordVerificationResult.SuccessRehashNeeded)
               await store.SetPasswordHashAsync(user, PasswordHasher.HashPassword(password));
    
            return verifyRes != PasswordVerificationResult.Failed;
        }
    }
    

提交回复
热议问题