Fix the authentication mechanism

Fix filter search
This commit is contained in:
2025-10-26 01:51:25 +08:00
parent 8513cbce55
commit 3e170ad526
10 changed files with 697 additions and 243 deletions

View File

@@ -299,8 +299,8 @@ func HashPasswordWithSalt(password, salt string) (string, error) {
// 将密码和盐值组合
combined := password + salt
// 使用bcrypt进行哈希成本因子12,平衡安全性和性能)
hashed, err := bcrypt.GenerateFromPassword([]byte(combined), 12)
// 使用bcrypt进行哈希成本因子10,平衡安全性和性能)
hashed, err := bcrypt.GenerateFromPassword([]byte(combined), 10)
if err != nil {
return "", err
}
@@ -321,3 +321,10 @@ func VerifyPasswordWithSalt(password, salt, hashedPassword string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(combined))
return err == nil
}
// GenerateSHA256Hash 生成字符串的SHA256哈希值
// 用于生成密码哈希摘要用于JWT验证
func GenerateSHA256Hash(input string) string {
hash := sha256.Sum256([]byte(input))
return fmt.Sprintf("%x", hash)
}