1 using Microsoft.AspNetCore.Identity;
3 using System.Security.Cryptography;
14 const uint SecureStringLength = 30;
27 this.passwordHasher = passwordHasher ??
throw new ArgumentNullException(nameof(passwordHasher));
33 using (var rng =
new RNGCryptoServiceProvider())
35 var byt =
new byte[amount];
45 throw new ArgumentNullException(nameof(user));
46 if (newPassword == null)
47 throw new ArgumentNullException(nameof(newPassword));
48 user.
PasswordHash = passwordHasher.HashPassword(user, newPassword);
56 switch (passwordHasher.VerifyHashedPassword(user, user.
PasswordHash, password))
58 case PasswordVerificationResult.Failed:
60 case PasswordVerificationResult.SuccessRehashNeeded:
61 SetUserPassword(user, password,
false);
68 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