diff options
author | 2021-08-12 21:03:24 +0200 | |
---|---|---|
committer | 2021-08-12 21:03:24 +0200 | |
commit | 98263a7de64269898a2f81207e38943b5c8e8653 (patch) | |
tree | 743c90f109a6c5d27832d1dcef2388d939f0f77a /vendor/github.com/wagslane/go-password-validator/validate.go | |
parent | Text duplication fix (#137) (diff) | |
download | gotosocial-98263a7de64269898a2f81207e38943b5c8e8653.tar.xz |
Grand test fixup (#138)
* start fixing up tests
* fix up tests + automate with drone
* fiddle with linting
* messing about with drone.yml
* some more fiddling
* hmmm
* add cache
* add vendor directory
* verbose
* ci updates
* update some little things
* update sig
Diffstat (limited to 'vendor/github.com/wagslane/go-password-validator/validate.go')
-rw-r--r-- | vendor/github.com/wagslane/go-password-validator/validate.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/github.com/wagslane/go-password-validator/validate.go b/vendor/github.com/wagslane/go-password-validator/validate.go new file mode 100644 index 000000000..c3bffe73b --- /dev/null +++ b/vendor/github.com/wagslane/go-password-validator/validate.go @@ -0,0 +1,75 @@ +package passwordvalidator + +import ( + "errors" + "fmt" + "strings" +) + +// Validate returns nil if the password has greater than or +// equal to the minimum entropy. If not, an error is returned +// that explains how the password can be strengthened. This error +// is safe to show the client +func Validate(password string, minEntropy float64) error { + entropy := getEntropy(password) + if entropy >= minEntropy { + return nil + } + + hasReplace := false + hasSep := false + hasOtherSpecial := false + hasLower := false + hasUpper := false + hasDigits := false + for _, c := range password { + if strings.ContainsRune(replaceChars, c) { + hasReplace = true + continue + } + if strings.ContainsRune(sepChars, c) { + hasSep = true + continue + } + if strings.ContainsRune(otherSpecialChars, c) { + hasOtherSpecial = true + continue + } + if strings.ContainsRune(lowerChars, c) { + hasLower = true + continue + } + if strings.ContainsRune(upperChars, c) { + hasUpper = true + continue + } + if strings.ContainsRune(digitsChars, c) { + hasDigits = true + continue + } + } + + allMessages := []string{} + + if !hasOtherSpecial || !hasSep || !hasReplace { + allMessages = append(allMessages, "including more special characters") + } + if !hasLower { + allMessages = append(allMessages, "using lowercase letters") + } + if !hasUpper { + allMessages = append(allMessages, "using uppercase letters") + } + if !hasDigits { + allMessages = append(allMessages, "using numbers") + } + + if len(allMessages) > 0 { + return fmt.Errorf( + "insecure password, try %v or using a longer password", + strings.Join(allMessages, ", "), + ) + } + + return errors.New("insecure password, try using a longer password") +} |