passphrase

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: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinWordsInDictionary = 256
	NumWordsMin          = 2
	NumWordsMax          = 32
)

Variables

View Source
var (
	ErrDictionaryTooSmall = errors.New(fmt.Sprintf("dictionary cannot have less than %d words after word-length restrictions are applied", MinWordsInDictionary))
	ErrNumWordsTooSmall   = errors.New(fmt.Sprintf("number of words cannot be less than %d", NumWordsMin))
	ErrNumWordsTooLarge   = errors.New(fmt.Sprintf("number of words cannot be more than %d", NumWordsMax))
	ErrWordLengthInvalid  = errors.New("word-length rule invalid")
)

Functions

func Generate added in v0.0.7

func Generate() string

Generate generates and returns a passphrase that follows the following rules: * uses an English Dictionary * uses capitalized words * uses a total of 3 words * injects a random number behind one of the words * uses "-" as the separator * ensures words used are between 4 and 7 characters long

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

type Rule func(g *generator)

Rule controls how the Generator/Sequencer generates passwords.

func WithCapitalizedWords

func WithCapitalizedWords(enabled bool) Rule

WithCapitalizedWords ensures the words are Capitalized.

func WithDictionary

func WithDictionary(words []string) Rule

func WithNumWords

func WithNumWords(n int) Rule

WithNumWords sets the number of words in the passphrase.

func WithNumber

func WithNumber(enabled bool) Rule

WithNumber injects a random number after one of the words in the passphrase.

func WithSeparator

func WithSeparator(s string) Rule

WithSeparator sets up the delimiter to separate words.

func WithWordLength

func WithWordLength(min, max int) Rule

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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