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 }