Created
November 18, 2017 08:56
-
-
Save jjwilliams42/5ee8078601ba47190871d7d0ad2bb692 to your computer and use it in GitHub Desktop.
Custom Password Hasher
This file contains hidden or 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
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