Skip to content

Commit 261b19c

Browse files
guillep2kzeripath
authored andcommitted
Backport: Fix password checks on admin create/edit user (#9076) (#9081)
* Fix password checks on admin create/edit user * Remove incorrect trimspace
1 parent 6ef0ab4 commit 261b19c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

routers/admin/users.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,14 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
9494
u.LoginName = form.LoginName
9595
}
9696
}
97-
if u.LoginType == models.LoginPlain {
97+
if u.LoginType == models.LoginNoType || u.LoginType == models.LoginPlain {
98+
if len(form.Password) < setting.MinPasswordLength {
99+
ctx.Data["Err_Password"] = true
100+
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplUserNew, &form)
101+
return
102+
}
98103
if !password.IsComplexEnough(form.Password) {
104+
ctx.Data["Err_Password"] = true
99105
ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserNew, &form)
100106
return
101107
}
@@ -203,14 +209,19 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
203209

204210
if len(form.Password) > 0 {
205211
var err error
206-
if u.Salt, err = models.GetUserSalt(); err != nil {
207-
ctx.ServerError("UpdateUser", err)
212+
if len(form.Password) < setting.MinPasswordLength {
213+
ctx.Data["Err_Password"] = true
214+
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplUserEdit, &form)
208215
return
209216
}
210217
if !password.IsComplexEnough(form.Password) {
211218
ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserEdit, &form)
212219
return
213220
}
221+
if u.Salt, err = models.GetUserSalt(); err != nil {
222+
ctx.ServerError("UpdateUser", err)
223+
return
224+
}
214225
u.HashPassword(form.Password)
215226
}
216227

0 commit comments

Comments
 (0)