summaryrefslogtreecommitdiffstats
path: root/modules/auth/password/password.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/auth/password/password.go')
-rw-r--r--modules/auth/password/password.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/modules/auth/password/password.go b/modules/auth/password/password.go
index 2172dc8b44..2c7205b708 100644
--- a/modules/auth/password/password.go
+++ b/modules/auth/password/password.go
@@ -5,8 +5,9 @@ package password
import (
"bytes"
- goContext "context"
+ "context"
"crypto/rand"
+ "errors"
"math/big"
"strings"
"sync"
@@ -15,6 +16,11 @@ import (
"code.gitea.io/gitea/modules/translation"
)
+var (
+ ErrComplexity = errors.New("password not complex enough")
+ ErrMinLength = errors.New("password not long enough")
+)
+
// complexity contains information about a particular kind of password complexity
type complexity struct {
ValidChars string
@@ -101,11 +107,14 @@ func Generate(n int) (string, error) {
}
buffer[j] = validChars[rnd.Int64()]
}
- pwned, err := IsPwned(goContext.Background(), string(buffer))
- if err != nil {
+
+ if err := IsPwned(context.Background(), string(buffer)); err != nil {
+ if errors.Is(err, ErrIsPwned) {
+ continue
+ }
return "", err
}
- if IsComplexEnough(string(buffer)) && !pwned && string(buffer[0]) != " " && string(buffer[n-1]) != " " {
+ if IsComplexEnough(string(buffer)) && string(buffer[0]) != " " && string(buffer[n-1]) != " " {
return string(buffer), nil
}
}