Documentation
¶
Overview ¶
Package strongword is a simple utility for validating password strengths against a provided set of rules.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultRules are the rules that are used if none are provided. DefaultRules = []Rule{ MinLength(8), CharsAndDigits(), SpecialChars(1), } )
Functions ¶
func Validate ¶
Validate validates the given word against the provided rules. If no rules are provided, the default rule set is used: MinLength(8), CharsAndDigits(), SpecialChars(1)
Example ¶
package main
import (
"fmt"
"regexp"
"github.com/bounoable/strongword"
)
func main() {
// Default rule set
errs := strongword.Validate("weakpassword")
// Custom rule set
errs = strongword.Validate(
"weakpassword",
strongword.MinLength(12),
strongword.SpecialChars(3),
strongword.Regexp(regexp.MustCompile("(?)[0-9]{4}")),
)
for _, err := range errs {
fmt.Println(err)
}
}
Types ¶
type CharsAndDigitsError ¶
type CharsAndDigitsError struct {
Detail string
}
CharsAndDigitsError means the provided word does not contain either any character or any digit.
func (CharsAndDigitsError) Error ¶
func (err CharsAndDigitsError) Error() string
type DigitsError ¶
DigitsError means the provided word does not contain enough digits.
func (DigitsError) Error ¶
func (err DigitsError) Error() string
type MinLengthError ¶
MinLengthError means the provided word is too short.
func (MinLengthError) Error ¶
func (err MinLengthError) Error() string
type RegexpError ¶
RegexpError means the provided word does match against a regular expression.
func (RegexpError) Error ¶
func (err RegexpError) Error() string
type Rule ¶
Rule is a validation rule.
func Characters ¶
Characters validates that a word contains any unicode point if chars at least min times.
func CharsAndDigits ¶
func CharsAndDigits() Rule
CharsAndDigits validates that a word does contain at least one character and one digit.
func SpecialChars ¶
SpecialChars validates the special character count in a word. Special characters are all charaters that are not latin-alphanumerical (a-z & 0-9).
type RunesError ¶
RunesError means the provided word does not contain enough runes of a given set.
func (RunesError) Error ¶
func (err RunesError) Error() string
type SpecialCharsError ¶
SpecialCharsError means the provided word does not contain enough special characters.
func (SpecialCharsError) Error ¶
func (err SpecialCharsError) Error() string