aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/admin
diff options
context:
space:
mode:
authorMaxim Tkachenko <maxim.tkachenko@gmail.com>2019-10-14 22:24:26 +0700
committerzeripath <art27@cantab.net>2019-10-14 16:24:26 +0100
commitdb657192d0349f7b10a62515fbf085d3a48d88f9 (patch)
treed298b9b2c487af61dc399774e67dcb3440add9c2 /routers/api/v1/admin
parentf9aba9ba0f07b77cb46dde6eda3c3f5b8fa841fe (diff)
downloadgitea-db657192d0349f7b10a62515fbf085d3a48d88f9.tar.gz
gitea-db657192d0349f7b10a62515fbf085d3a48d88f9.zip
Password Complexity Checks (#6230)
Add password complexity checks. The default settings require a lowercase, uppercase, number and a special character within passwords. Co-Authored-By: T-M-A <maxim.tkachenko@gmail.com> Co-Authored-By: Lanre Adelowo <adelowomailbox@gmail.com> Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-Authored-By: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'routers/api/v1/admin')
-rw-r--r--routers/api/v1/admin/user.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index 70076b626b..f35ad297b0 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -6,9 +6,12 @@
package admin
import (
+ "errors"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/password"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/convert"
"code.gitea.io/gitea/routers/api/v1/user"
@@ -73,7 +76,11 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
if ctx.Written() {
return
}
-
+ if !password.IsComplexEnough(form.Password) {
+ err := errors.New("PasswordComplexity")
+ ctx.Error(400, "PasswordComplexity", err)
+ return
+ }
if err := models.CreateUser(u); err != nil {
if models.IsErrUserAlreadyExist(err) ||
models.IsErrEmailAlreadyUsed(err) ||
@@ -131,6 +138,11 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
}
if len(form.Password) > 0 {
+ if !password.IsComplexEnough(form.Password) {
+ err := errors.New("PasswordComplexity")
+ ctx.Error(400, "PasswordComplexity", err)
+ return
+ }
var err error
if u.Salt, err = models.GetUserSalt(); err != nil {
ctx.Error(500, "UpdateUser", err)