-
-
Save svenrog/c14461901ee5136a20f3df56af664466 to your computer and use it in GitHub Desktop.
Hasher that will fall back to legacy hashing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Identity; | |
namespace YourProject.Infrastructure.Security | |
{ | |
public class FallbackPasswordHasher<TUser> : PasswordHasher<TUser> | |
where TUser : class | |
{ | |
public override PasswordVerificationResult VerifyHashedPassword(TUser user, string hashedPassword, string providedPassword) | |
{ | |
var result = base.VerifyHashedPassword(user, hashedPassword, providedPassword); | |
if (result == PasswordVerificationResult.Success) | |
return result; | |
if (LegacyAspNetIdentityCrypto.VerifyHashedPassword(hashedPassword, providedPassword)) | |
// NOTE: You can either accept the hash as is, like | |
// return PasswordVerificationResult.Success; | |
// or return that a rehash is needed (to update the hash), | |
// this will look like the first attempt is a fail, the second attempt will be a success | |
return PasswordVerificationResult.SuccessRehashNeeded; | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment