1 using Microsoft.AspNetCore.Identity;
4 using System.Security.Cryptography;
15 const uint SecureStringLength = 30;
28 this.passwordHasher = passwordHasher ??
throw new ArgumentNullException(nameof(passwordHasher));
34 using (var rng =
new RNGCryptoServiceProvider())
36 var byt =
new byte[amount];
46 throw new ArgumentNullException(nameof(user));
47 if (newPassword == null)
48 throw new ArgumentNullException(nameof(newPassword));
49 user.
PasswordHash = passwordHasher.HashPassword(user, newPassword);
57 var result = passwordHasher.VerifyHashedPassword(user, user.
PasswordHash, password);
60 case PasswordVerificationResult.Failed:
62 case PasswordVerificationResult.SuccessRehashNeeded:
63 SetUserPassword(user, password,
false);
65 case PasswordVerificationResult.Success:
68 throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
"Password hasher return unknown PasswordVerificationResult: {0}", result));
75 public string GetSecureString() => Convert.ToBase64String(GetSecureBytes(SecureStringLength));
string PasswordHash
The hash of the user's password
Use server authentication
readonly IPasswordHasher< User > passwordHasher
The IPasswordHasher<TUser> for the CryptographySuite
DateTimeOffset LastPasswordUpdate
When PasswordHash was last changed
void SetUserPassword(User user, string newPassword, bool newUser)
Sets a User.PasswordHash for a given user
Contains various cryptographic functions
bool CheckUserPassword(User user, string password)
Checks a given password matches a given user 's User.PasswordHash. This may result in User...
byte[] GetSecureBytes(uint amount)
Generates a secure set of bytes
CryptographySuite(IPasswordHasher< User > passwordHasher)
Construct a CryptographySuite