first commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user