Skip to content

Commit

Permalink
feat: add password validation to CreateUser function
Browse files Browse the repository at this point in the history
- Add validation for password requirement in CreateUser function

Signed-off-by: appleboy <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Dec 18, 2023
1 parent cb31e62 commit 4d14927
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions routers/api/v1/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ func CreateUser(ctx *context.APIContext) {
if ctx.Written() {
return
}

if u.LoginType == auth.Plain && len(form.Password) == 0 {
err := errors.New("PasswordIsRequired")
ctx.Error(http.StatusBadRequest, "PasswordIsRequired", err)
return
}

if !password.IsComplexEnough(form.Password) {
err := errors.New("PasswordComplexity")
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
Expand Down

0 comments on commit 4d14927

Please sign in to comment.