diff options
author | Joe Chen <jc@unknwon.io> | 2022-10-23 19:15:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-23 19:15:14 +0800 |
commit | c58c89362161718e1079b9d43c0ce984bb1506cc (patch) | |
tree | 14a54295b60b4c2887f06bfde8b7e603e0f4d6dd /internal/route/user | |
parent | ef0388045f8fd35a40b3404deb3caa1a37e103f7 (diff) |
refactor(db): migrate password methods off `user.go` (#7205)
Diffstat (limited to 'internal/route/user')
-rw-r--r-- | internal/route/user/auth.go | 3 | ||||
-rw-r--r-- | internal/route/user/setting.go | 4 |
2 files changed, 4 insertions, 3 deletions
diff --git a/internal/route/user/auth.go b/internal/route/user/auth.go index 213ff050..d06a7488 100644 --- a/internal/route/user/auth.go +++ b/internal/route/user/auth.go @@ -19,6 +19,7 @@ import ( "gogs.io/gogs/internal/email" "gogs.io/gogs/internal/form" "gogs.io/gogs/internal/tool" + "gogs.io/gogs/internal/userutil" ) const ( @@ -554,7 +555,7 @@ func ResetPasswdPost(c *context.Context) { c.Error(err, "get user salt") return } - u.EncodePassword() + u.Password = userutil.EncodePassword(u.Password, u.Salt) if err := db.UpdateUser(u); err != nil { c.Error(err, "update user") return diff --git a/internal/route/user/setting.go b/internal/route/user/setting.go index aae38d60..cdb5eee2 100644 --- a/internal/route/user/setting.go +++ b/internal/route/user/setting.go @@ -198,7 +198,7 @@ func SettingsPasswordPost(c *context.Context, f form.ChangePassword) { return } - if !c.User.ValidatePassword(f.OldPassword) { + if !userutil.ValidatePassword(c.User.Password, c.User.Salt, f.OldPassword) { c.Flash.Error(c.Tr("settings.password_incorrect")) } else if f.Password != f.Retype { c.Flash.Error(c.Tr("form.password_not_match")) @@ -209,7 +209,7 @@ func SettingsPasswordPost(c *context.Context, f form.ChangePassword) { c.Errorf(err, "get user salt") return } - c.User.EncodePassword() + c.User.Password = userutil.EncodePassword(c.User.Password, c.User.Salt) if err := db.UpdateUser(c.User); err != nil { c.Errorf(err, "update user") return |