]> source.dussan.org Git - gitea.git/commitdiff
Whenever the password is updated ensure that the hash algorithm is too (#13966)
authorzeripath <art27@cantab.net>
Sat, 12 Dec 2020 18:59:49 +0000 (18:59 +0000)
committerGitHub <noreply@github.com>
Sat, 12 Dec 2020 18:59:49 +0000 (19:59 +0100)
`user.HashPassword` may potentially - and in fact now likely does - change
the `passwd_hash_algo` therefore whenever the `passwd` is updated, this
also needs to be updated.

Fix #13832

Thanks @fblaese for the hint

Signed-off-by: Andrew Thornton <art27@cantab.net>
cmd/admin.go
routers/user/auth.go
routers/user/setting/account.go

index 8989ec2ebd192312d69fad501438160890187f3f..6b8c26fc0cd6f36ce357f4fae15230dfe071608f 100644 (file)
@@ -335,7 +335,7 @@ func runChangePassword(c *cli.Context) error {
        }
        user.HashPassword(c.String("password"))
 
-       if err := models.UpdateUserCols(user, "passwd", "salt"); err != nil {
+       if err := models.UpdateUserCols(user, "passwd", "passwd_hash_algo", "salt"); err != nil {
                return err
        }
 
index 38e90cbef1d26776b7d219a4e4aed509d240b0ae..1e340994118c59e5760fde990ca91b48b369caff 100644 (file)
@@ -1514,7 +1514,7 @@ func ResetPasswdPost(ctx *context.Context) {
        }
        u.HashPassword(passwd)
        u.MustChangePassword = false
-       if err := models.UpdateUserCols(u, "must_change_password", "passwd", "rands", "salt"); err != nil {
+       if err := models.UpdateUserCols(u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
                ctx.ServerError("UpdateUser", err)
                return
        }
@@ -1590,7 +1590,7 @@ func MustChangePasswordPost(ctx *context.Context, cpt *captcha.Captcha, form aut
        u.HashPassword(form.Password)
        u.MustChangePassword = false
 
-       if err := models.UpdateUserCols(u, "must_change_password", "passwd", "salt"); err != nil {
+       if err := models.UpdateUserCols(u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
                ctx.ServerError("UpdateUser", err)
                return
        }
index 9b72e2a31a23fb752556482434a1bff6b4298d4f..4fb2e4be402eeff5c1736660523176f0d032744f 100644 (file)
@@ -68,7 +68,7 @@ func AccountPost(ctx *context.Context, form auth.ChangePasswordForm) {
                        return
                }
                ctx.User.HashPassword(form.Password)
-               if err := models.UpdateUserCols(ctx.User, "salt", "passwd"); err != nil {
+               if err := models.UpdateUserCols(ctx.User, "salt", "passwd_hash_algo", "passwd"); err != nil {
                        ctx.ServerError("UpdateUser", err)
                        return
                }