forked from mtusi2026/mtusi2026lab2
ЛР 2: PostgreSQL, сессии, Redis и исследование
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Isopoh.Cryptography.Argon2;
|
||||
|
||||
namespace Messenger.Api.Services;
|
||||
|
||||
public sealed class PasswordService
|
||||
{
|
||||
public string Hash(string password)
|
||||
{
|
||||
var salt = RandomNumberGenerator.GetBytes(16);
|
||||
var config = new Argon2Config
|
||||
{
|
||||
Type = Argon2Type.HybridAddressing,
|
||||
Version = Argon2Version.Nineteen,
|
||||
TimeCost = 3,
|
||||
MemoryCost = 32768,
|
||||
Lanes = 1,
|
||||
Threads = 1,
|
||||
Password = Encoding.UTF8.GetBytes(password),
|
||||
Salt = salt,
|
||||
HashLength = 32
|
||||
};
|
||||
return Argon2.Hash(config);
|
||||
}
|
||||
|
||||
public bool Verify(string hash, string password) => Argon2.Verify(hash, password);
|
||||
}
|
||||
Reference in New Issue
Block a user