Skip to content

Commit 9595eee

Browse files
committed
Added minimum password length to app.ini
1 parent b2cce12 commit 9595eee

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

conf/app.ini

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ COOKIE_USERNAME = gitea_awesome
169169
COOKIE_REMEMBER_NAME = gitea_incredible
170170
; Reverse proxy authentication header name of user name
171171
REVERSE_PROXY_AUTHENTICATION_USER = X-WEBAUTH-USER
172+
; Sets the minimum password length for new Users
173+
MIN_PASSWORD_LENGTH = 6
172174

173175
[service]
174176
ACTIVE_CODE_LIVE_MINUTES = 180

conf/locale/locale_en-US.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ send_reset_mail = Click here to (re)send your password reset email
162162
reset_password = Reset Your Password
163163
invalid_code = Sorry, your confirmation code has expired or not valid.
164164
reset_password_helper = Click here to reset your password
165-
password_too_short = Password length cannot be less then 6.
165+
password_too_short = Password length cannot be less then %d.
166166
non_local_account = Non-local accounts cannot change passwords through Gitea.
167167

168168
[mail]

modules/setting/setting.go

+6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ var (
9393
CookieUserName string
9494
CookieRememberName string
9595
ReverseProxyAuthUser string
96+
MinPasswordLength int
9697

9798
// Database settings
9899
UseSQLite3 bool
@@ -468,6 +469,11 @@ please consider changing to GITEA_CUSTOM`)
468469
CookieUserName = sec.Key("COOKIE_USERNAME").String()
469470
CookieRememberName = sec.Key("COOKIE_REMEMBER_NAME").String()
470471
ReverseProxyAuthUser = sec.Key("REVERSE_PROXY_AUTHENTICATION_USER").MustString("X-WEBAUTH-USER")
472+
MinPasswordLength = sec.Key("MIN_PASSWORD_LENGTH").MustInt()
473+
474+
if MinPasswordLength == 0 {
475+
MinPasswordLength = 6
476+
}
471477

472478
sec = Cfg.Section("attachment")
473479
AttachmentPath = sec.Key("PATH").MustString(path.Join(AppDataPath, "attachments"))

routers/user/auth.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
203203
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplSignUp, &form)
204204
return
205205
}
206+
if len(form.Password) < setting.MinPasswordLength {
207+
ctx.Data["Err_Password"] = true
208+
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplSignUp, &form)
209+
return
210+
}
206211

207212
u := &models.User{
208213
Name: form.UserName,
@@ -406,7 +411,7 @@ func ResetPasswd(ctx *context.Context) {
406411
ctx.HTML(200, tplResetPassword)
407412
}
408413

409-
// ResetPasswdPost response fro reset password request
414+
// ResetPasswdPost response from reset password request
410415
func ResetPasswdPost(ctx *context.Context) {
411416
ctx.Data["Title"] = ctx.Tr("auth.reset_password")
412417

@@ -420,10 +425,10 @@ func ResetPasswdPost(ctx *context.Context) {
420425
if u := models.VerifyUserActiveCode(code); u != nil {
421426
// Validate password length.
422427
passwd := ctx.Query("password")
423-
if len(passwd) < 6 {
428+
if len(passwd) < setting.MinPasswordLength {
424429
ctx.Data["IsResetForm"] = true
425430
ctx.Data["Err_Password"] = true
426-
ctx.RenderWithErr(ctx.Tr("auth.password_too_short"), tplResetPassword, nil)
431+
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplResetPassword, nil)
427432
return
428433
}
429434

0 commit comments

Comments
 (0)