1 Star 0 Fork 0

fredgo/tools

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hash.go 566 Bytes
一键复制 编辑 原始数据 按行查看 历史
fredgo 提交于 2025-08-25 23:34 +08:00 . init
/**
* @author: fred
* @doc:
*/
package encrypt
import (
"crypto/md5"
"encoding/hex"
"golang.org/x/crypto/bcrypt"
)
func Md5(str []byte) string {
h := md5.New()
h.Write(str)
return hex.EncodeToString(h.Sum(nil))
}
// hash加密
func GenPasswordHash(password []byte) ([]byte, error) {
return bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
}
// hash校验
func ValidatePasswordHash(password string, hashed string) bool {
if err := bcrypt.CompareHashAndPassword([]byte(hashed), []byte(password)); err != nil {
return false
}
return true
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fredgo/tools.git
git@gitee.com:fredgo/tools.git
fredgo
tools
tools
0cc84fb7326f

搜索帮助