Add tool dir.

This commit is contained in:
zicla
2019-04-26 03:08:22 +08:00
parent aed1ee2001
commit c5de9ce9eb
28 changed files with 23 additions and 22 deletions

View File

@ -0,0 +1,30 @@
package util
import (
"crypto/md5"
"fmt"
"golang.org/x/crypto/bcrypt"
)
//给密码字符串加密
func GetMd5(raw string) string {
return fmt.Sprintf("%x", md5.Sum([]byte(raw)))
}
func GetBcrypt(raw string) string {
password := []byte(raw)
hashedPassword, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
if err != nil {
panic(err)
}
return string(hashedPassword)
}
func MatchBcrypt(raw string, bcryptStr string) bool {
err := bcrypt.CompareHashAndPassword([]byte(bcryptStr), []byte(raw))
return err == nil
}