1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-08 03:04:29 +00:00

Backport: Fix password checks on admin create/edit user (#9076) (#9081)

* Fix password checks on admin create/edit user

* Remove incorrect trimspace
This commit is contained in:
guillep2k 2019-11-19 21:08:53 -03:00 committed by zeripath
parent 6ef0ab4d96
commit 261b19ced7

View File

@ -94,8 +94,14 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
u.LoginName = form.LoginName u.LoginName = form.LoginName
} }
} }
if u.LoginType == models.LoginPlain { if u.LoginType == models.LoginNoType || u.LoginType == models.LoginPlain {
if len(form.Password) < setting.MinPasswordLength {
ctx.Data["Err_Password"] = true
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplUserNew, &form)
return
}
if !password.IsComplexEnough(form.Password) { if !password.IsComplexEnough(form.Password) {
ctx.Data["Err_Password"] = true
ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserNew, &form) ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserNew, &form)
return return
} }
@ -203,14 +209,19 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
if len(form.Password) > 0 { if len(form.Password) > 0 {
var err error var err error
if u.Salt, err = models.GetUserSalt(); err != nil { if len(form.Password) < setting.MinPasswordLength {
ctx.ServerError("UpdateUser", err) ctx.Data["Err_Password"] = true
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplUserEdit, &form)
return return
} }
if !password.IsComplexEnough(form.Password) { if !password.IsComplexEnough(form.Password) {
ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserEdit, &form) ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserEdit, &form)
return return
} }
if u.Salt, err = models.GetUserSalt(); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
u.HashPassword(form.Password) u.HashPassword(form.Password)
} }