password

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyCharset         = errors.New("cannot generate passwords with empty charset")
	ErrInvalidN             = errors.New("value of N exceeds valid range")
	ErrMinLowerCaseTooLong  = errors.New("minimum number of lower-case characters requested longer than password")
	ErrMinUpperCaseTooLong  = errors.New("minimum number of upper-case characters requested longer than password")
	ErrMinSymbolsTooLong    = errors.New("minimum number of symbols requested longer than password")
	ErrNoLowerCaseInCharset = errors.New("found no lower-case characters to use in charset")
	ErrNoUpperCaseInCharset = errors.New("found no upper-case characters to use in charset")
	ErrNoSymbolsInCharset   = errors.New("found no symbols to use in charset")
	ErrRequirementsNotMet   = errors.New("minimum number of lower-case+upper-case+symbols requested longer than password")
	ErrZeroLenPassword      = errors.New("cannot generate passwords with 0 length")
)

Functions

func Generate added in v0.0.7

func Generate() string

Generate generates and returns a password that follows the following rules: * uses the AllChars charset * ensures the password is 12 characters long * uses a minimum of 3 lower case characters * uses a minimum of 1 upper case character * uses one symbol character

func SetSeed added in v0.0.7

func SetSeed(seed uint64)

SetSeed sets the seed value used by the RNG of the default Generator.

Types

type Generator

type Generator interface {
	// Generate returns a randomly generated password.
	Generate() string
	// SetSeed overrides the seed value for the RNG.
	SetSeed(seed uint64)
}

func NewGenerator

func NewGenerator(rules ...Rule) (Generator, error)

NewGenerator returns a password generator that implements the Generator interface.

type Rule added in v0.0.3

type Rule func(g *generator)

Rule controls how the Generator/Sequencer generates passwords.

func WithCharset added in v0.0.3

func WithCharset(c charset.Charset) Rule

WithCharset sets the Charset the Generator/Sequencer can use.

func WithLength added in v0.0.3

func WithLength(l int) Rule

WithLength sets the length of the generated password.

func WithMinLowerCase added in v0.0.5

func WithMinLowerCase(min int) Rule

WithMinLowerCase controls the minimum number of lower case characters that can appear in the password.

Note: This works only on a Generator and is ineffective with a Sequencer.

func WithMinUpperCase added in v0.0.5

func WithMinUpperCase(min int) Rule

WithMinUpperCase controls the minimum number of upper case characters that can appear in the password.

Note: This works only on a Generator and is ineffective with a Sequencer.

func WithNumSymbols added in v0.0.3

func WithNumSymbols(min, max int) Rule

WithNumSymbols controls the min/max number of symbols that can appear in the password.

Note: This works only on a Generator and is ineffective with a Sequencer.

Jump to

Keyboard shortcuts

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