From edd0b30e0872ccdbd3c566bb1e3c4cda4e31d89e Mon Sep 17 00:00:00 2001 From: Vickko Date: Fri, 11 Jul 2025 19:57:55 +0800 Subject: [PATCH] feat: Supports smooth migration of password hash (#3940) --- object/check.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/object/check.go b/object/check.go index 3f47a3de..906442e4 100644 --- a/object/check.go +++ b/object/check.go @@ -252,7 +252,7 @@ func CheckPassword(user *User, password string, lang string, options ...bool) er credManager := cred.GetCredManager(passwordType) if credManager == nil { - return fmt.Errorf(i18n.Translate(lang, "check:unsupported password type: %s"), organization.PasswordType) + return fmt.Errorf(i18n.Translate(lang, "check:unsupported password type: %s"), passwordType) } if organization.MasterPassword != "" { @@ -265,6 +265,16 @@ func CheckPassword(user *User, password string, lang string, options ...bool) er return recordSigninErrorInfo(user, lang, enableCaptcha) } + isOutdated := passwordType != organization.PasswordType + if isOutdated { + user.Password = password + user.UpdateUserPassword(organization) + _, err = UpdateUser(user.GetId(), user, []string{"password", "password_type", "password_salt"}, true) + if err != nil { + return err + } + } + return resetUserSigninErrorTimes(user) }