You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool/ncrypt/bcrypt.go

19 lines
451 B
Go

package ncrypt
import "golang.org/x/crypto/bcrypt"
// BcryptEncrypt Bcrypt 加密
func BcryptEncrypt(password string, code int) string {
if code == 0 {
code = bcrypt.DefaultCost
}
bs, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(bs)
}
// BcryptCheck Bcrypt 检查
func BcryptCheck(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}