namespace WebApp.Authentication;
///
/// Utility class for generating BCrypt password hashes for use in User Secrets configuration.
///
public static class PasswordHashGenerator
{
///
/// Generates a BCrypt hash for the given password with work factor 11.
///
/// The password to hash
/// BCrypt hash string suitable for storing in User Secrets
public static string GenerateHash(string password)
{
return BCrypt.Net.BCrypt.HashPassword(password, workFactor: 11);
}
///
/// Generates hashes for multiple passwords at once.
///
/// Dictionary of label/password pairs
/// Dictionary of label/hash pairs
public static Dictionary GenerateHashes(Dictionary passwords)
{
var results = new Dictionary();
foreach (var kvp in passwords)
{
results[kvp.Key] = GenerateHash(kvp.Value);
}
return results;
}
}