From b248828a63faf9a4412b1906666cebeb47fa3fc7 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 29 Aug 2023 16:12:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=8A=A0=E5=AF=86=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/utils/crypto/crypto.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/core/utils/crypto/crypto.go diff --git a/lib/core/utils/crypto/crypto.go b/lib/core/utils/crypto/crypto.go new file mode 100644 index 00000000..c242f7f5 --- /dev/null +++ b/lib/core/utils/crypto/crypto.go @@ -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 +}