generator

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	MinLength = 5
	MaxLength = 128
	MinWords  = 3
	MaxWords  = 20
)

Bounds of the rules.

Variables

View Source
var (
	ErrLength    = errors.New("password length out of range")
	ErrWords     = errors.New("passphrase word count out of range")
	ErrNoCharset = errors.New("no character set selected")
	ErrCharset   = errors.New("unknown character set")
)

Rule errors.

Functions

This section is empty.

Types

type Charset

type Charset uint8

Charset is a class of characters a password draws from.

const (
	Lowercase Charset = iota
	Uppercase
	Digits
	Symbols
)

The character classes.

func (Charset) Alphabet

func (c Charset) Alphabet(avoidAmbiguous bool) string

Alphabet is the characters c draws from, without the easily confused ones when avoidAmbiguous is set.

type Charsets

type Charsets struct {
	// contains filtered or unexported fields
}

Charsets is a non-empty set of character classes; the zero value holds every class.

func NewCharsets

func NewCharsets(cs ...Charset) (Charsets, error)

NewCharsets is the set of cs, which must name at least one class.

func (Charsets) Has

func (s Charsets) Has(c Charset) bool

Has reports whether c is in the set.

func (Charsets) List

func (s Charsets) List() []Charset

List is the set's classes in declaration order.

type Length

type Length struct {
	// contains filtered or unexported fields
}

Length is a password length within [MinLength, MaxLength]; the zero value is MinLength.

func NewLength

func NewLength(n int) (Length, error)

NewLength validates a password length.

func (Length) Int

func (l Length) Int() int

Int is the length in characters.

type Passphrase

type Passphrase struct {
	Words      Words
	Separator  string
	Capitalize bool
	Number     bool
}

Passphrase is the rules of a passphrase of words from the EFF large wordlist, joined by Separator, each capitalised when Capitalize is set, one of them followed by a digit when Number is set.

func (Passphrase) Generate

func (p Passphrase) Generate(random io.Reader) (string, error)

Generate draws a passphrase from random.

type Password

type Password struct {
	Length         Length
	Charsets       Charsets
	AvoidAmbiguous bool
}

Password is the rules of a random-character password: every class in Charsets appears at least once.

func (Password) Generate

func (p Password) Generate(random io.Reader) (string, error)

Generate draws a password from random.

type Words

type Words struct {
	// contains filtered or unexported fields
}

Words is a passphrase word count within [MinWords, MaxWords]; the zero value is MinWords.

func NewWords

func NewWords(n int) (Words, error)

NewWords validates a passphrase word count.

func (Words) Int

func (w Words) Int() int

Int is the number of words.

Jump to

Keyboard shortcuts

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