From ccd7093bd2b171811e8bd94a4dba614f9bdd45d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A4=E9=B8=BF?= <31199914+wsczx@users.noreply.github.com> Date: Fri, 7 Mar 2025 04:39:22 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=8A=A0=E5=AF=86=E5=BC=80?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/dbdata/user.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/server/dbdata/user.go b/server/dbdata/user.go index 02967b9..f710f5f 100644 --- a/server/dbdata/user.go +++ b/server/dbdata/user.go @@ -207,16 +207,18 @@ func CheckOtp(name, otp, secret string) bool { // 插入数据库前加密密码 func (u *User) BeforeInsert() { - hashedPassword, err := utils.PasswordHash(u.PinCode) - if err != nil { - base.Error(err) - } - u.PinCode = hashedPassword -} - -// 更新数据库前加密密码 -func (u *User) BeforeUpdate() { - if len(u.PinCode) != 60 { + if base.Cfg.EncryptionPassword { + hashedPassword, err := utils.PasswordHash(u.PinCode) + if err != nil { + base.Error(err) + } + u.PinCode = hashedPassword + } +} + +// 更新数据库前加密密码 +func (u *User) BeforeUpdate() { + if len(u.PinCode) != 60 && base.Cfg.EncryptionPassword { hashedPassword, err := utils.PasswordHash(u.PinCode) if err != nil { base.Error(err)