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