28 lines
899 B
C#
28 lines
899 B
C#
using System.Security.Cryptography;
|
||
using System.Text;
|
||
using F9WebAiTest.Application.Interfaces.Security;
|
||
|
||
namespace F9WebAiTest.Infrastructure.InterfaceImplements.Security;
|
||
|
||
/// <summary>密码哈希服务实现(BCrypt)</summary>
|
||
public class PasswordHasher : IPasswordHasher
|
||
{
|
||
public string Hash256(string input)
|
||
{
|
||
var bytes = SHA256.HashData(Encoding.UTF8.GetBytes(input ?? ""));
|
||
return Convert.ToHexString(bytes).ToLowerInvariant();
|
||
}
|
||
|
||
public string GetMd5Hash(string input)
|
||
{
|
||
var bytes = MD5.HashData(Encoding.UTF8.GetBytes(input ?? ""));
|
||
return Convert.ToHexString(bytes).ToLowerInvariant();
|
||
}
|
||
|
||
public string HashPassword(string password)
|
||
=> BCrypt.Net.BCrypt.HashPassword(password);
|
||
|
||
public bool VerifyPassword(string password, string hashedPassword)
|
||
=> BCrypt.Net.BCrypt.Verify(password, hashedPassword);
|
||
}
|