Skip to content

Commit ad43b11

Browse files
zeripathjolheiser
andauthored
Add Password Algorithm option to install page (#14701)
Add Password Algorithm option to install page Fix #14674 Co-authored-by: John Olheiser <john.olheiser@gmail.com>
1 parent 66a148e commit ad43b11

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

models/user.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,17 @@ const (
5656
algoScrypt = "scrypt"
5757
algoArgon2 = "argon2"
5858
algoPbkdf2 = "pbkdf2"
59+
)
60+
61+
// AvailableHashAlgorithms represents the available password hashing algorithms
62+
var AvailableHashAlgorithms = []string{
63+
algoPbkdf2,
64+
algoArgon2,
65+
algoScrypt,
66+
algoBcrypt,
67+
}
5968

69+
const (
6070
// EmailNotificationsEnabled indicates that the user would like to receive all email notifications
6171
EmailNotificationsEnabled = "enabled"
6272
// EmailNotificationsOnMention indicates that the user would like to be notified via email when mentioned.

modules/forms/user_form.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ type InstallForm struct {
6060
DefaultEnableTimetracking bool
6161
NoReplyAddress string
6262

63+
PasswordAlgorithm string
64+
6365
AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
6466
AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
6567
AdminConfirmPasswd string

options/locale/locale_en-US.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ default_enable_timetracking = Enable Time Tracking by Default
205205
default_enable_timetracking_popup = Enable time tracking for new repositories by default.
206206
no_reply_address = Hidden Email Domain
207207
no_reply_address_helper = Domain name for users with a hidden email address. For example, the username 'joe' will be logged in Git as 'joe@noreply.example.org' if the hidden email domain is set to 'noreply.example.org'.
208+
password_algorithm = Password Hash Algorithm
209+
password_algorithm_helper = Set the password hashing algorithm. Algorithms have differing requirements and strength. `argon2` whilst having good characteristics uses a lot of memory and may be inappropriate for small systems.
208210
209211
[home]
210212
uname_holder = Username or Email Address
@@ -931,7 +933,7 @@ ext_issues = Ext. Issues
931933
ext_issues.desc = Link to an external issue tracker.
932934
933935
projects = Projects
934-
projects.desc = Manage issues and pulls in project boards.
936+
projects.desc = Manage issues and pulls in project boards.
935937
projects.description = Description (optional)
936938
projects.description_placeholder = Description
937939
projects.create = Create Project

routers/install.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func InstallInit(next http.Handler) http.Handler {
6666
"TmplLoadTimes": func() string {
6767
return time.Since(startTime).String()
6868
},
69+
"PasswordHashAlgorithms": models.AvailableHashAlgorithms,
6970
},
7071
}
7172
ctx.Req = context.WithContext(req, &ctx)
@@ -142,6 +143,7 @@ func Install(ctx *context.Context) {
142143
form.DefaultAllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization
143144
form.DefaultEnableTimetracking = setting.Service.DefaultEnableTimetracking
144145
form.NoReplyAddress = setting.Service.NoReplyAddress
146+
form.PasswordAlgorithm = setting.PasswordHashAlgo
145147

146148
middleware.AssignForm(form, ctx.Data)
147149
ctx.HTML(200, tplInstall)
@@ -185,6 +187,8 @@ func InstallPost(ctx *context.Context) {
185187
setting.Database.Charset = form.Charset
186188
setting.Database.Path = form.DbPath
187189

190+
setting.PasswordHashAlgo = form.PasswordAlgorithm
191+
188192
if (setting.Database.Type == "sqlite3") &&
189193
len(setting.Database.Path) == 0 {
190194
ctx.Data["Err_DbPath"] = true
@@ -380,6 +384,9 @@ func InstallPost(ctx *context.Context) {
380384
return
381385
}
382386
cfg.Section("security").Key("SECRET_KEY").SetValue(secretKey)
387+
if len(form.PasswordAlgorithm) > 0 {
388+
cfg.Section("security").Key("PASSWORD_HASH_ALGO").SetValue(form.PasswordAlgorithm)
389+
}
383390

384391
err = os.MkdirAll(filepath.Dir(setting.CustomConf), os.ModePerm)
385392
if err != nil {

templates/install.tmpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,20 @@
267267
<input id="_no_reply_address" name="no_reply_address" value="{{.no_reply_address}}">
268268
<span class="help">{{.i18n.Tr "install.no_reply_address_helper"}}</span>
269269
</div>
270+
<div class="inline field">
271+
<label for="password_algorithm">{{.i18n.Tr "install.password_algorithm"}}</label>
272+
<div class="ui selection dropdown">
273+
<input id="password_algorithm" type="hidden" name="password_algorithm" value="{{.password_algorithm}}">
274+
<div class="text">{{.password_algorithm}}</div>
275+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
276+
<div class="menu">
277+
{{range .PasswordHashAlgorithms}}
278+
<div class="item" data-value="{{.}}">{{.}}</div>
279+
{{end}}
280+
</div>
281+
</div>
282+
<span class="help">{{.i18n.Tr "install.password_algorithm_helper"}}</span>
283+
</div>
270284
</div>
271285
</div>
272286

0 commit comments

Comments
 (0)