Skip to content

Commit

Permalink
更改密码验证算法为SHA512
Browse files Browse the repository at this point in the history
在SaltPasswordProvider类中,将md5+sha512模式下的密码验证算法从SHA1改为SHA512。
  • Loading branch information
猿人易 committed Dec 12, 2024
1 parent b914fbc commit 324cae9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions NewLife.Core/Security/IPasswordProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected virtual String CreateSalt()
/// <param name="password">传输密码。可能是明文、MD5</param>
/// <param name="hash">哈希密文。服务端数据库保存,带有算法、盐值、哈希值</param>
/// <returns></returns>
public Boolean Verify(String password, String hash)
public virtual Boolean Verify(String password, String hash)
{
var ss = hash?.Split('$');
if (ss == null || ss.Length == 0) throw new ArgumentNullException(nameof(hash));
Expand Down Expand Up @@ -139,7 +139,7 @@ public Boolean Verify(String password, String hash)
return ss[3] == password.GetBytes().SHA1(salt.GetBytes()).ToBase64();
case "md5+sha512":
if (ss[3] == password.GetBytes().SHA512(salt.GetBytes()).ToBase64()) return true;
return ss[3] == password.MD5().GetBytes().SHA1(salt.GetBytes()).ToBase64();
return ss[3] == password.MD5().GetBytes().SHA512(salt.GetBytes()).ToBase64();
default:
throw new NotSupportedException($"Unsupported password hash mode [{ss[1]}]");
}
Expand Down

0 comments on commit 324cae9

Please sign in to comment.