密码加密工具

This commit is contained in:
TsMask
2023-08-29 16:12:24 +08:00
parent bb343355bd
commit b248828a63

View File

@@ -0,0 +1,20 @@
package crypto
import (
"golang.org/x/crypto/bcrypt"
)
// BcryptHash Bcrypt密码加密
func BcryptHash(originStr string) string {
hash, err := bcrypt.GenerateFromPassword([]byte(originStr), bcrypt.DefaultCost)
if err != nil {
return ""
}
return string(hash)
}
// BcryptCompare Bcrypt密码匹配检查
func BcryptCompare(originStr, hashStr string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hashStr), []byte(originStr))
return err == nil
}