I am using the following code to hash passwords using Pbkdf2:
private string HashPassword(string password)
{
// generate a 128-bit salt using a secure PRNG
byte[] salt = new byte[128 / 8];
using (var rng = RandomNumberGenerator.Create())
{
rng.GetBytes(salt);
}
// derive a 256-bit subkey (use HMACSHA1 with 10,000 iterations)
string hashedPassword = Convert.ToBase64String(KeyDerivation.Pbkdf2(
password: password,
salt: salt,
prf: KeyDerivationPrf.HMACSHA1,
iterationCount: 10000,
numBytesRequested: 256 / 8));
return hashedPassword;
}
How do I verify the password for authentication? It seems I need to get the salt used to hash the password. How do I get that? Please note that I am not using a separate field to store the hash. Only the hashed password is stored in the database.