Skip to content

Commit 61b8974

Browse files
zeripathdelvhjolheiserlunny
authored
Provide the ability to set password hash algorithm parameters (#22942)
This PR refactors and improves the password hashing code within gitea and makes it possible for server administrators to set the password hashing parameters In addition it takes the opportunity to adjust the settings for `pbkdf2` in order to make the hashing a little stronger. The majority of this work was inspired by PR #14751 and I would like to thank @boppy for their work on this. Thanks to @Gusted for the suggestion to adjust the `pbkdf2` hashing parameters. Close #14751 --------- Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: delvh <[email protected]> Co-authored-by: John Olheiser <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent d5e417a commit 61b8974

27 files changed

+871
-152
lines changed

cmd/admin_user_change_password.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"fmt"
1010

1111
user_model "code.gitea.io/gitea/models/user"
12-
pwd "code.gitea.io/gitea/modules/password"
12+
pwd "code.gitea.io/gitea/modules/auth/password"
1313
"code.gitea.io/gitea/modules/setting"
1414

1515
"github.com/urfave/cli"

cmd/admin_user_create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
auth_model "code.gitea.io/gitea/models/auth"
1212
user_model "code.gitea.io/gitea/models/user"
13-
pwd "code.gitea.io/gitea/modules/password"
13+
pwd "code.gitea.io/gitea/modules/auth/password"
1414
"code.gitea.io/gitea/modules/setting"
1515
"code.gitea.io/gitea/modules/util"
1616

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,22 @@ Certain queues have defaults that override the defaults set in `[queue]` (this o
568568
- `IMPORT_LOCAL_PATHS`: **false**: Set to `false` to prevent all users (including admin) from importing local path on server.
569569
- `INTERNAL_TOKEN`: **\<random at every install if no uri set\>**: Secret used to validate communication within Gitea binary.
570570
- `INTERNAL_TOKEN_URI`: **<empty>**: Instead of defining INTERNAL_TOKEN in the configuration, this configuration option can be used to give Gitea a path to a file that contains the internal token (example value: `file:/etc/gitea/internal_token`)
571-
- `PASSWORD_HASH_ALGO`: **pbkdf2**: The hash algorithm to use \[argon2, pbkdf2, scrypt, bcrypt\], argon2 will spend more memory than others.
571+
- `PASSWORD_HASH_ALGO`: **pbkdf2**: The hash algorithm to use \[argon2, pbkdf2, pbkdf2_v1, pbkdf2_hi, scrypt, bcrypt\], argon2 and scrypt will spend significant amounts of memory.
572+
- Note: The default parameters for `pbkdf2` hashing have changed - the previous settings are available as `pbkdf2_v1` but are not recommended.
573+
- The hash functions may be tuned by using `$` after the algorithm:
574+
- `argon2$<time>$<memory>$<threads>$<key-length>`
575+
- `bcrypt$<cost>`
576+
- `pbkdf2$<iterations>$<key-length>`
577+
- `scrypt$<n>$<r>$<p>$<key-length>`
578+
- The defaults are:
579+
- `argon2`: `argon2$2$65536$8$50`
580+
- `bcrypt`: `bcrypt$10`
581+
- `pbkdf2`: `pbkdf2$50000$50`
582+
- `pbkdf2_v1`: `pbkdf2$10000$50`
583+
- `pbkdf2_v2`: `pbkdf2$50000$50`
584+
- `pbkdf2_hi`: `pbkdf2$320000$50`
585+
- `scrypt`: `scrypt$65536$16$2$50`
586+
- Adjusting the algorithm parameters using this functionality is done at your own risk.
572587
- `CSRF_COOKIE_HTTP_ONLY`: **true**: Set false to allow JavaScript to read CSRF cookie.
573588
- `MIN_PASSWORD_LENGTH`: **6**: Minimum password length for new users.
574589
- `PASSWORD_COMPLEXITY`: **off**: Comma separated list of character classes required to pass minimum complexity. If left empty or no valid values are specified, checking is disabled (off):

0 commit comments

Comments
 (0)