From c58c89362161718e1079b9d43c0ce984bb1506cc Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sun, 23 Oct 2022 19:15:14 +0800 Subject: refactor(db): migrate password methods off `user.go` (#7205) --- internal/route/user/auth.go | 3 ++- internal/route/user/setting.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'internal/route/user') 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 -- cgit v1.2.3