This repository has been archived on 2025-10-08. You can view files and clone it, but cannot push or open issues or pull requests.
miniauthold/vendor/github.com/go-passwd/validator/contains_at_least.go
kekskurse 7b5df08e45
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/playwright Pipeline was successful
ci/woodpecker/push/deplyoment Pipeline was successful
chore: password validation
2025-03-13 21:12:16 +01:00

23 lines
599 B
Go

package validator
import (
"fmt"
"strings"
)
// ContainsAtLeast returns a ValidateFunc that count occurrences of a chars and compares it with required value
func ContainsAtLeast(chars string, occurrences int, customError error) ValidateFunc {
return ValidateFunc(func(password string) error {
cnt := 0
for _, char := range strings.Split(chars, "") {
cnt += strings.Count(password, char)
}
if cnt < occurrences {
if customError != nil {
return customError
}
return fmt.Errorf("Password must contains at least %d chars from %s", occurrences, chars)
}
return nil
})
}