diff --git a/framework/NPin.Framework.Core/Crypt/BCrypt/BCrypt.cs b/framework/NPin.Framework.Core/Crypt/BCrypt/BCrypt.cs index ac6e9f6..9b682bc 100644 --- a/framework/NPin.Framework.Core/Crypt/BCrypt/BCrypt.cs +++ b/framework/NPin.Framework.Core/Crypt/BCrypt/BCrypt.cs @@ -1,4 +1,5 @@ -using System.Text; +using System.Security.Cryptography; +using System.Text; namespace NPin.Framework.Core.Crypt.BCrypt; @@ -11,4 +12,29 @@ public static class BCrypt return Org.BouncyCastle.Crypto.Generators.BCrypt.Generate(passBytes, saltBytes, cost); } + + public static string GenerateSalt() + { + var buf = new byte[16]; + using var rand = RandomNumberGenerator.Create(); + rand.GetBytes(buf); + + return Convert.ToBase64String(buf); + } + + /// + /// 检查密码是否正确 + /// 通过再次生成一次密码匹配 + /// + /// + /// + /// + /// + /// + public static bool Check(string encrypt, string password, string salt, int cost) + { + var passStr = Generate(password, salt, cost).ToString(); + + return string.Equals(encrypt, passStr); + } } \ No newline at end of file