mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
test to make server
This commit is contained in:
@@ -1,16 +1,32 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Govor.Application.Interfaces.Authentication;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Govor.Application.Services.Authentication;
|
||||
|
||||
public class JwtTokenHasher : IJwtTokenHasher
|
||||
{
|
||||
private readonly string _pepper;
|
||||
|
||||
public JwtTokenHasher(IConfiguration config)
|
||||
{
|
||||
_pepper = config["EncryptionOption:Secret"] ?? "D1fault%Lxng%Randxm^Secret^Key(123!";
|
||||
}
|
||||
|
||||
public string HashToken(string token)
|
||||
{
|
||||
return BCrypt.Net.BCrypt.HashPassword(token, workFactor: 13);
|
||||
using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(_pepper));
|
||||
var bytes = Encoding.UTF8.GetBytes(token);
|
||||
var hash = hmac.ComputeHash(bytes);
|
||||
return Convert.ToBase64String(hash);
|
||||
}
|
||||
|
||||
public bool VerifyToken(string token, string storedHash)
|
||||
{
|
||||
return BCrypt.Net.BCrypt.Verify(token, storedHash);
|
||||
var currentHashBytes = Encoding.UTF8.GetBytes(HashToken(token));
|
||||
var storedHashBytes = Encoding.UTF8.GetBytes(storedHash);
|
||||
|
||||
return CryptographicOperations.FixedTimeEquals(currentHashBytes, storedHashBytes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user