From fa756c25fe085cb4a9c39aca355d2cbabc3579bd Mon Sep 17 00:00:00 2001 From: black1552 Date: Mon, 2 Mar 2026 14:18:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(utils):=20=E6=B7=BB=E5=8A=A0MD5=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=8A=A0=E5=AF=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入gmd5包用于MD5加密 - 实现Md5Password函数对密码进行MD5加密 - 处理加密过程中的错误情况 - 返回空字符串当加密失败时 --- .idea/GOHCache.xml | 2 +- utils/bcrypt.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.idea/GOHCache.xml b/.idea/GOHCache.xml index ac86a46..4319817 100644 --- a/.idea/GOHCache.xml +++ b/.idea/GOHCache.xml @@ -383,7 +383,7 @@ - diff --git a/utils/bcrypt.go b/utils/bcrypt.go index 4ff8e8e..b9c6648 100644 --- a/utils/bcrypt.go +++ b/utils/bcrypt.go @@ -3,6 +3,7 @@ package utils import ( "fmt" + "github.com/gogf/gf/v2/crypto/gmd5" "golang.org/x/crypto/bcrypt" ) @@ -21,3 +22,11 @@ func ValidPassword(hashPassword, password string) error { } return nil } + +func Md5Password(password string) string { + md5pass, err := gmd5.EncryptString(password) + if err != nil { + return "" + } + return md5pass +}