Skip to content

Commit f27d87d

Browse files
Bwkolunny
authored andcommitted
Added minimum password length to app.ini (#223)
1 parent d0932ef commit f27d87d

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
@@ -168,6 +168,8 @@ COOKIE_USERNAME = gitea_awesome
168168
COOKIE_REMEMBER_NAME = gitea_incredible
169169
; Reverse proxy authentication header name of user name
170170
REVERSE_PROXY_AUTHENTICATION_USER = X-WEBAUTH-USER
171+
; Sets the minimum password length for new Users
172+
MIN_PASSWORD_LENGTH = 6
171173

172174
[service]
173175
ACTIVE_CODE_LIVE_MINUTES = 180

modules/setting/setting.go

+6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ var (
9696
CookieUserName string
9797
CookieRememberName string
9898
ReverseProxyAuthUser string
99+
MinPasswordLength int
99100

100101
// Database settings
101102
UseSQLite3 bool
@@ -589,6 +590,11 @@ please consider changing to GITEA_CUSTOM`)
589590
CookieUserName = sec.Key("COOKIE_USERNAME").MustString("gitea_awesome")
590591
CookieRememberName = sec.Key("COOKIE_REMEMBER_NAME").MustString("gitea_incredible")
591592
ReverseProxyAuthUser = sec.Key("REVERSE_PROXY_AUTHENTICATION_USER").MustString("X-WEBAUTH-USER")
593+
MinPasswordLength = sec.Key("MIN_PASSWORD_LENGTH").MustInt()
594+
595+
if MinPasswordLength == 0 {
596+
MinPasswordLength = 6
597+
}
592598

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

options/locale/locale_en-US.ini

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

171171
[mail]

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,
@@ -410,7 +415,7 @@ func ResetPasswd(ctx *context.Context) {
410415
ctx.HTML(200, tplResetPassword)
411416
}
412417

413-
// ResetPasswdPost response fro reset password request
418+
// ResetPasswdPost response from reset password request
414419
func ResetPasswdPost(ctx *context.Context) {
415420
ctx.Data["Title"] = ctx.Tr("auth.reset_password")
416421

@@ -424,10 +429,10 @@ func ResetPasswdPost(ctx *context.Context) {
424429
if u := models.VerifyUserActiveCode(code); u != nil {
425430
// Validate password length.
426431
passwd := ctx.Query("password")
427-
if len(passwd) < 6 {
432+
if len(passwd) < setting.MinPasswordLength {
428433
ctx.Data["IsResetForm"] = true
429434
ctx.Data["Err_Password"] = true
430-
ctx.RenderWithErr(ctx.Tr("auth.password_too_short"), tplResetPassword, nil)
435+
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplResetPassword, nil)
431436
return
432437
}
433438

0 commit comments

Comments
 (0)