Authentication Service

This commit is contained in:
dingo
2025-11-10 09:01:46 -05:00
parent 72bc097a71
commit a45cc41f4a
16 changed files with 1016 additions and 23 deletions
+24
View File
@@ -0,0 +1,24 @@
using System.Security.Cryptography;
namespace Server.Services.Auth;
public sealed class Pbkdf2PasswordHasher : IPasswordHasher
{
private const int SaltSize = 32;
private const int HashSize = 64;
private const int Iterations = 150_000; // good default; tune for your hardware
public void Hash(string password, out byte[] hash, out byte[] salt)
{
salt = RandomNumberGenerator.GetBytes(SaltSize);
using var pbkdf2 = new Rfc2898DeriveBytes(password, salt, Iterations, HashAlgorithmName.SHA256);
hash = pbkdf2.GetBytes(HashSize);
}
public bool Verify(string password, byte[] hash, byte[] salt)
{
using var pbkdf2 = new Rfc2898DeriveBytes(password, salt, Iterations, HashAlgorithmName.SHA256);
var test = pbkdf2.GetBytes(HashSize);
return CryptographicOperations.FixedTimeEquals(test, hash);
}
}