Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom Password Hasher
public class CustomPasswordHasher : IPasswordHasher
{
public IPasswordHasher<User> AspNetPasswordHasher { get; set; }
public byte Version => throw new NotImplementedException();
public CustomPasswordHasher(IPasswordHasher<User> ph)
{
AspNetPasswordHasher = ph;
}
public string HashPassword(string password)
{
return AspNetPasswordHasher.HashPassword(null, password);
}
public bool VerifyPassword(string hashedPassword, string providedPassword, out bool needsRehash)
{
var result = AspNetPasswordHasher.VerifyHashedPassword(null, hashedPassword, providedPassword);
needsRehash = false;
switch (result)
{
case PasswordVerificationResult.SuccessRehashNeeded:
case PasswordVerificationResult.Success:
needsRehash = true;
return true;
case PasswordVerificationResult.Failed:
return false;
default:
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.