init: init refactor

This commit is contained in:
Blizzard
2026-04-27 00:02:18 +08:00
commit e515f6a287
360 changed files with 30713 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
package hash
import (
"crypto/md5"
"encoding/hex"
"golang.org/x/crypto/bcrypt"
)
// BcryptHash 使用bcrypt对密码进行加密
func BcryptHash(password string) string {
bytes, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(bytes)
}
// BcryptCheck 对比明文密码和数据库的哈希值
func BcryptCheck(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}
// MD5 计算MD5哈希值
func MD5(str []byte) string {
h := md5.New()
h.Write(str)
return hex.EncodeToString(h.Sum(nil))
}