policy

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// WithDefault is a default policy.
	WithDefault = NewPolicy(
		[]rune(lowercase+uppercase+numbers+symbols),
		regexpValidator{regexpString: regexp.QuoteMeta("a-zA-Z0-9!#$%&'\"()*+,-./:;<=>?@[\\]^_`{|}~")})

	// WithLowercase is a policy with lowercase.
	WithLowercase = NewPolicy([]rune(lowercase), regexpValidator{regexpString: "a-z"})

	// WithUppercase is a policy with uppercase.
	WithUppercase = NewPolicy([]rune(uppercase), regexpValidator{regexpString: "A-Z"})

	// WithNumbers is a policy with numbers.
	WithNumbers = NewPolicy([]rune(numbers), regexpValidator{regexpString: "0-9"})

	// WithSymbols is a policy with symbols.
	WithSymbols = NewPolicy(
		[]rune(symbols),
		regexpValidator{regexpString: regexp.QuoteMeta("a-zA-Z0-9!#$%&'\"()*+,-./:;<=>?@[\\]^_`{|}~")})

	// WithMinLength is a policy with minimum length.
	WithMinLength = func(min int) Policy {
		return NewPolicy([]rune{}, minLengthValidator{minLength: min})
	}

	// WithMaxLength is a policy with maximum length.
	WithMaxLength = func(max int) Policy {
		return NewPolicy([]rune{}, maxLengthValidator{maxLength: max})
	}

	// WithCustomString is a policy with custom string.
	WithCustomString = func(letters []rune) Policy {
		return NewPolicy(letters,
			regexpValidator{regexpString: regexp.QuoteMeta(string(letters))})
	}
)

Functions

This section is empty.

Types

type Policy

type Policy interface {
	Validator
	Letters() []rune
}

Policy is a password policy.

func NewPolicy

func NewPolicy(letters []rune, validator Validator) Policy

NewPolicy returns a new policy.

type Validator

type Validator interface {
	IsValid(password string) bool
}

Validator is a validator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL