using System;
using System.Security.Cryptography;
class Program
{
static void Main()
{
string password = "SecurePassword123!@";
string storedHash = HashPassword(password);
Console.Write("Hash: ");
Console.WriteLine(storedHash);
}
// Hash a password using PBKDF2-HMAC-SHA256
public static string HashPassword(string password) {
byte[] salt = new byte[16];
using (var rng = RandomNumberGenerator.Create()) {
rng.GetBytes(salt);
}
var pbkdf2 = new Rfc2898DeriveBytes(
password,
salt,
100000,
HashAlgorithmName.SHA256
);
byte[] hash = pbkdf2.GetBytes(32);
return Convert.ToBase64String(salt) + ":" + Convert.ToBase64String(hash);
}
}
/*
run:
Hash: kq9Gd7YprY1PDpyAj0BObg==:n6o8DIsdhsiFnR9jq93PR6oUBBk68rwYCZGCpgzeP9s=
*/