-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Password Complexity Checks #6230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 133 commits
Commits
Show all changes
150 commits
Select commit
Hold shift + click to select a range
1b11649
Password Complexity Checks
T-M-A 0127fee
Merge branch 'master' into pwd-complexity
T-M-A b4210cb
fix unit test
T-M-A 18061a7
Merge branch 'pwd-complexity' of github.com:T-M-A/gitea into pwd-comp…
T-M-A 0af5b63
Update options/locale/locale_en-US.ini
adelowo f49a9a1
upgrade password check
T-M-A 2aae5b5
Merge branch 'pwd-complexity' of github.com:T-M-A/gitea into pwd-comp…
T-M-A 789b25b
Merge branch 'master' into pwd-complexity
T-M-A 68811f0
Little refactoring
T-M-A 8e3845d
xMerge branch 'pwd-complexity' of github.com:T-M-A/gitea into pwd-com…
T-M-A bf749da
Merge branch 'master' into pwd-complexity
T-M-A a976460
fix 1
b6e7bd8
fix
3fc779c
fix pointers for checks
T-M-A 244a6db
fix
T-M-A f297248
Merge branch 'master' into pwd-complexity
T-M-A 7360ab6
fix admin/user/update
T-M-A 560d28a
fix admin/user checks
T-M-A 3a67b60
Merge branch 'pwd-complexity' of github.com:T-M-A/gitea into pwd-comp…
T-M-A 82ff291
Merge branch 'master' into pwd-complexity
T-M-A 3da4b38
fix ResetPasswd
T-M-A 285ec84
Merge branch 'pwd-complexity' of github.com:T-M-A/gitea into pwd-comp…
T-M-A c7239cf
Add checks for CLI and API
T-M-A 0e560ca
Merge branch 'master' into pwd-complexity
T-M-A 5c0687a
Change algorimt for generate.GetRandomString
T-M-A 46c172b
Merge branch 'master' into pwd-complexity
T-M-A 7524102
fix imports
T-M-A 789785b
fix linter errors
T-M-A f89bc50
fix for fmt-check
T-M-A c6fbca5
fix
T-M-A 09447b4
little randomize
T-M-A 8d2d146
Refactoriing code
T-M-A c14729f
Merge branch 'master' into pwd-complexity
T-M-A 25c7a93
Merge branch 'master' into pwd-complexity
T-M-A 5b3421b
fix build errors
T-M-A 4e1b02e
Merge branch 'pwd-complexity' of github.com:T-M-A/gitea into pwd-comp…
T-M-A 5868a03
fix build errors
T-M-A 4e2e3cc
Merge branch 'master' into pwd-complexity
T-M-A 27e14a2
fix
T-M-A 1867476
Merge branch 'master' into pwd-complexity
T-M-A 224b2db
fix 2
T-M-A 6879f31
Merge branch 'master' into pwd-complexity
techknowlogick fefc620
fix fmt-check
T-M-A f7a2a6b
Merge branch 'master' into pwd-complexity
T-M-A 2611c9d
Update modules/generate/generate.go
T-M-A 81b2f3d
Merge branch 'master' into pwd-complexity
T-M-A 1503486
fix errors
T-M-A 54d2ec4
Merge branch 'master' into pwd-complexity
T-M-A 5af7ec6
Merge branch 'master' into pwd-complexity
T-M-A 23058cb
Merge branch 'master' into pwd-complexity
T-M-A d587490
Merge branch 'master' into pwd-complexity
T-M-A 2b8977b
Merge branch 'master' into pwd-complexity
T-M-A 7c10353
Merge branch 'master' into pwd-complexity
T-M-A 1d4bd25
Merge branch 'master' into pwd-complexity
T-M-A 24ae039
Merge branch 'master' into pwd-complexity
T-M-A 1cd9b8a
Merge branch 'master' into pwd-complexity
T-M-A f257bb0
Merge branch 'master' into pwd-complexity
T-M-A bad2849
Merge branch 'master' into pwd-complexity
T-M-A 9ab9616
Merge branch 'master' into pwd-complexity
T-M-A 7968f29
Merge branch 'master' into pwd-complexity
T-M-A 77e3d62
Merge branch 'master' into pwd-complexity
T-M-A 7378d63
Merge branch 'master' into pwd-complexity
T-M-A 082826d
Merge branch 'master' into pwd-complexity
T-M-A 0dd151c
Merge branch 'master' into pwd-complexity
T-M-A 93af680
fix formats
T-M-A 831898e
Merge branch 'master' into pwd-complexity
T-M-A 43ddc3c
Merge branch 'master' into pwd-complexity
T-M-A 1441526
Merge branch 'master' into pwd-complexity
T-M-A 9cdd02c
Merge branch 'master' into pwd-complexity
T-M-A 49fb8c0
Merge branch 'master' into pwd-complexity
T-M-A 35e9ff0
Merge branch 'master' into pwd-complexity
T-M-A cd5ead4
Merge branch 'master' into pwd-complexity
T-M-A 744fe82
Merge branch 'master' into pwd-complexity
T-M-A c4122b7
Merge branch 'master' into pwd-complexity
T-M-A d04abea
Merge branch 'master' into pwd-complexity
T-M-A 166a6e7
Merge branch 'master' into pwd-complexity
T-M-A f154129
Merge branch 'master' into pwd-complexity
T-M-A 7dcfa0a
Merge branch 'master' into pwd-complexity
T-M-A 95b3f52
Merge branch 'master' into pwd-complexity
T-M-A 3d6072a
Merge branch 'master' into pwd-complexity
T-M-A f505001
Merge branch 'master' into pwd-complexity
T-M-A 370fb39
Merge branch 'master' into pwd-complexity
T-M-A a22346f
Merge branch 'master' into pwd-complexity
T-M-A 0da6b77
Merge branch 'master' into pwd-complexity
T-M-A 7a93e41
Merge branch 'master' into pwd-complexity
T-M-A 952d288
Merge branch 'master' into pwd-complexity
T-M-A 3d8b19c
Merge branch 'master' into pwd-complexity
T-M-A 5260fb0
Merge branch 'master' into pwd-complexity
T-M-A 4e87d0e
Fix for merge
T-M-A 0ab72d9
Merge branch 'master' into pwd-complexity
T-M-A 08fa9e9
Fix sample configuration file
T-M-A 5a57340
Merge branch 'master' into pwd-complexity
T-M-A 2c70cc8
Merge branch 'master' into pwd-complexity
T-M-A 326d515
Fix comment for sample setting
T-M-A 4ee7bd4
If setting is null - do not check complexity
T-M-A cde04fd
Fix locale
T-M-A 9d55861
remove special chars in regexp pattern
T-M-A fbb2756
update special chars list
T-M-A f180425
# Conflicts:
T-M-A b73e1a8
Merge branch 'master' into pwd-complexity
T-M-A fc9ef53
fix fmt
T-M-A cf2644e
Merge branch 'master' into pwd-complexity
T-M-A 66e416b
Minor fixes
T-M-A 8abd9b6
Minor fixes
T-M-A 4e65110
Minor fixes
T-M-A a129719
Merge remote-tracking branch 'origin/pwd-complexity' into pwd-complexity
T-M-A 6762604
Minor fixes and rename generate.GeneratePassword for golang-lint pass
T-M-A 183e22c
Adding more variants for test
T-M-A d6ee579
Merge branch 'master' into pwd-complexity
T-M-A ba6e8ab
Merge branch 'master' into pwd-complexity
T-M-A f7184f8
Fix for use default values.
T-M-A ffb8c71
Merge branch 'pwd-complexity' of github.com:T-M-A/gitea into pwd-comp…
T-M-A a7541de
Merge branch 'master' into pwd-complexity
T-M-A 5817b42
Update cheat sheet
T-M-A e545efa
Merge branch 'pwd-complexity' of github.com:T-M-A/gitea into pwd-comp…
T-M-A 51c3655
Merge branch 'master' into pwd-complexity
T-M-A 8608600
Update docs/content/doc/advanced/config-cheat-sheet.en-us.md
T-M-A c84f1a9
Update custom/conf/app.ini.sample
T-M-A 7be7d0b
Update cmd/admin.go
T-M-A 0bb4d3c
Merge branch 'master' into pwd-complexity
T-M-A d863e4e
Merge branch 'master' into pwd-complexity
T-M-A 6e41130
Merge branch 'master' into pwd-complexity
T-M-A e0d9ea7
fix fmt
T-M-A 1019fe8
Merge branch 'pwd-complexity' of github.com:T-M-A/gitea into pwd-comp…
T-M-A 6279b71
Move to standalone package, refactoring generate function
T-M-A 0240b00
Move to standalone package, refactoring generate function
T-M-A 191c435
Move to standalone package, refactoring generate function
T-M-A 59f2a89
fix imports
T-M-A 5cd4168
Move to standalone package, refactoring generate function
T-M-A c67be56
Move to standalone package, refactoring generate function
T-M-A af8e700
Move to standalone package, refactoring generate function, rename fun…
T-M-A 8f4f1f5
Update modules/setting/setting.go
T-M-A fa41105
Merge branch 'master' into pwd-complexity
techknowlogick 189153e
Update modules/setting/setting.go
T-M-A 3374ada
Add broken call initDB()
T-M-A 957eaac
Add broken call initDB()
T-M-A d9bf639
Merge branch 'master' into pwd-complexity
lunny 048dd01
Increased the number of special characters
T-M-A cf4ba9e
Update modules/password/password.go
T-M-A 91267a1
Increased the number of special characters and space symbol. Checked …
zeripath 51708bf
Increased the number of special characters and space symbol. Checked …
T-M-A d86a869
Merge branch 'master' into pwd-complexity
lunny 26bc832
Update docs/content/doc/advanced/config-cheat-sheet.en-us.md
T-M-A dab06db
Update modules/setting/setting.go
T-M-A bfb3793
Merge branch 'master' into pwd-complexity
lafriks 48e2515
Merge branch 'master' into pwd-complexity
sapk e531c7d
Merge branch 'master' into pwd-complexity
T-M-A 4eda987
Merge branch 'master' into pwd-complexity
lunny d20d9f7
Merge branch 'master' into pwd-complexity
lafriks b9b2cee
Merge branch 'master' into pwd-complexity
T-M-A File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package password | ||
T-M-A marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"crypto/rand" | ||
"math/big" | ||
"regexp" | ||
"sync" | ||
|
||
"code.gitea.io/gitea/modules/setting" | ||
) | ||
|
||
var matchComplexities = map[string]regexp.Regexp{} | ||
var matchComplexityOnce sync.Once | ||
var validChars string | ||
|
||
var validComplexities = map[string]string{ | ||
"lower": "abcdefghijklmnopqrstuvwxyz", | ||
"upper": "ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
"digit": "0123456789", | ||
"spec": "_-", | ||
T-M-A marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// NewComplexity for preparation | ||
func NewComplexity() { | ||
matchComplexityOnce.Do(func() { | ||
if len(setting.PasswordComplexity) > 0 { | ||
for key, val := range setting.PasswordComplexity { | ||
matchComplexity := regexp.MustCompile(val) | ||
T-M-A marked this conversation as resolved.
Show resolved
Hide resolved
|
||
matchComplexities[key] = *matchComplexity | ||
validChars += validComplexities[key] | ||
} | ||
} else { | ||
for _, val := range validComplexities { | ||
validChars += val | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// IsComplexEnough return True if password is Complexity | ||
func IsComplexEnough(pwd string) bool { | ||
if len(setting.PasswordComplexity) > 0 { | ||
NewComplexity() | ||
for _, val := range matchComplexities { | ||
if !val.MatchString(pwd) { | ||
return false | ||
} | ||
} | ||
} | ||
return true | ||
} | ||
|
||
// Generate a random password | ||
func Generate(n int) (string, error) { | ||
NewComplexity() | ||
buffer := make([]byte, n) | ||
T-M-A marked this conversation as resolved.
Show resolved
Hide resolved
|
||
max := big.NewInt(int64(len(validChars))) | ||
for { | ||
for j := 0; j < n; j++ { | ||
rnd, err := rand.Int(rand.Reader, max) | ||
if err != nil { | ||
return "", err | ||
} | ||
buffer[j] = validChars[rnd.Int64()] | ||
} | ||
if IsComplexEnough(string(buffer)) { | ||
return string(buffer), nil | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.