Files
f9-web-ai-test/backend/F9WebAiTest.Infrastructure/InterfaceImplements/Security/PasswordHasher.cs
T
2026-10-08 10:43:59 +08:00

28 lines
899 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}