Skip to content

Instantly share code, notes, and snippets.

@jjwilliams42
Created November 18, 2017 08:56
Show Gist options
  • Save jjwilliams42/5ee8078601ba47190871d7d0ad2bb692 to your computer and use it in GitHub Desktop.
Save jjwilliams42/5ee8078601ba47190871d7d0ad2bb692 to your computer and use it in GitHub Desktop.
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