1 Star 0 Fork 0

szmaozi/go-utils

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
crypt.go 750 Bytes
Copy Edit Raw Blame History
szmaozi authored 2021-09-15 19:28 . wip: e, crypt
package utils
import (
"crypto/md5"
"fmt"
"golang.org/x/crypto/bcrypt"
)
func GeneSalt() string {
return RandomString(8)
}
//GenePwdHash 给密码就行加密操作
func GenPwdHash(userPassword string) (string, error) {
hash, err := bcrypt.GenerateFromPassword([]byte(userPassword), bcrypt.DefaultCost)
if err != nil {
return "", err
}
return string(hash), nil
}
//ValidatePwd 密码比对
func ValidatePwd(userPassword string, hashed string) bool {
if err := bcrypt.CompareHashAndPassword([]byte(hashed), []byte(userPassword)); err != nil {
return false
}
return true
}
func Hash(s string) string {
md5Inst := md5.New()
md5Inst.Write([]byte(s))
res := md5Inst.Sum(nil)
// return string(res)
return fmt.Sprintf("%x", res)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/szmaozi/go-utils.git
git@gitee.com:szmaozi/go-utils.git
szmaozi
go-utils
go-utils
29e02a007caf

Search