Skip to content

Commit

Permalink
Fix password checks on admin create/edit user (#9076)
Browse files Browse the repository at this point in the history
* Fix password checks on admin create/edit user

* Remove incorrect trimspace
  • Loading branch information
guillep2k authored and zeripath committed Nov 20, 2019
1 parent 4a357f4 commit e4ec32d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions routers/admin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
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) {
ctx.Data["Err_Password"] = true
ctx.RenderWithErr(password.BuildComplexityError(ctx), tplUserNew, &form)
return
}
Expand Down Expand Up @@ -203,14 +209,19 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {

if len(form.Password) > 0 {
var err error
if u.Salt, err = models.GetUserSalt(); err != nil {
ctx.ServerError("UpdateUser", err)
if len(form.Password) < setting.MinPasswordLength {
ctx.Data["Err_Password"] = true
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplUserEdit, &form)
return
}
if !password.IsComplexEnough(form.Password) {
ctx.RenderWithErr(password.BuildComplexityError(ctx), tplUserEdit, &form)
return
}
if u.Salt, err = models.GetUserSalt(); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
u.HashPassword(form.Password)
}

Expand Down

0 comments on commit e4ec32d

Please sign in to comment.