mirror of
https://github.com/gopasspw/gopass.git
synced 2026-05-30 11:18:48 +02:00
16c071a780
Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
57 lines
1020 B
Go
57 lines
1020 B
Go
package pwgen
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// containsAllClasses validates that the password contains at least one
|
|
// character from each given character class. Can also contain other classes.
|
|
func containsAllClasses(pw string, classes ...string) bool {
|
|
CLASSES:
|
|
for _, class := range classes {
|
|
for _, ch := range class {
|
|
if strings.Contains(pw, string(ch)) {
|
|
continue CLASSES
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// containsOnlyClasses validates that the password only contains characters
|
|
// from the given classes. Must not satisfy all classes.
|
|
func containsOnlyClasses(pw string, classes ...string) bool {
|
|
for _, c := range pw {
|
|
for _, class := range classes {
|
|
if !strings.Contains(class, string(c)) {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func containsMaxConsecutive(pw string, n int) bool {
|
|
last := ""
|
|
repCnt := 1
|
|
|
|
for _, r := range pw {
|
|
if last == string(r) {
|
|
repCnt++
|
|
if repCnt >= n {
|
|
return false
|
|
}
|
|
} else {
|
|
repCnt = 1
|
|
}
|
|
|
|
last = string(r)
|
|
}
|
|
|
|
return true
|
|
}
|