2using System.Globalization;
3using System.Security.Cryptography;
5using Microsoft.AspNetCore.Identity;
36 using var rng = RandomNumberGenerator.Create();
37 var byt =
new byte[amount];
45 ArgumentNullException.ThrowIfNull(user);
46 ArgumentNullException.ThrowIfNull(newPassword);
47 user.PasswordHash =
passwordHasher.HashPassword(user, newPassword);
49 user.LastPasswordUpdate = DateTimeOffset.UtcNow;
55 ArgumentNullException.ThrowIfNull(user);
56 ArgumentNullException.ThrowIfNull(password);
59 throw new ArgumentException(
"user must have PasswordHash!", nameof(user));
64 case PasswordVerificationResult.Failed:
66 case PasswordVerificationResult.SuccessRehashNeeded:
69 case PasswordVerificationResult.Success:
72 throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
"Password hasher return unknown PasswordVerificationResult: {0}", result));
string? PasswordHash
The hash of the user's password.
bool CheckUserPassword(User user, string password)
Checks a given password matches a given user 's User.PasswordHash. This may result in User....
void SetUserPassword(User user, string newPassword, bool newUser)
Sets a User.PasswordHash for a given user .
string GetSecureString()
Generates a 40-length secure ascii string.A 40-length secure ascii string.
CryptographySuite(IPasswordHasher< User > passwordHasher)
Initializes a new instance of the CryptographySuite class.
const uint SecureStringLength
Length in bytes of generated base64 secure string.
byte[] GetSecureBytes(uint amount)
Generates a secure set of bytes.A secure set of bytes.
readonly IPasswordHasher< User > passwordHasher
The IPasswordHasher<TUser> for the CryptographySuite.
Contains various cryptographic functions.