Documentation
¶
Overview ¶
Package passgen provides several cryptographicaly secure pseudorandom pass{word,phrase} generator methods.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrLength = errors.New("passgen: invalid password length") ErrSet = errors.New("passgen: character set is empty") ErrDict = errors.New("passgen: dictionary is empty") )
var Base32Alphabet *base32.Encoding = base32.StdEncoding
Base32Alphabet is the encoding alphabet used by the Base32 generator function. Base32Alphabet defaults to base32.StdEncoding (see RFC 4648).
var Rng io.Reader = rand.Reader
Rng is a global instance of a random reader, used by the random password generator functions in this package. Reader defaults to the cryptographically secure pseudorandom generator in crypto/rand.
Functions ¶
func Ascii ¶
Ascii generates a uniformly distributed random ASCII string with length n. The password space consists of printable ASCII chars and can be narrowed down with the CharSet bitmask s.
Example ¶
password, err := Ascii(20, SetComplete&^SetSymbol) if err != nil { log.Fatal(err) } fmt.Printf("Generated password: %q\n", password)
Output:
func Diceware ¶
Diceware selects n random words from the specified dictionary reader dict. Words are separated with the sep parameter (usually "" or " "). The dictionary source format is one word per line. Aside from the generated passphrase, the dictionary size m (i.e. number of selectable words) is returned. This can be useful for determining the entropy of the resulting passphrase (See the Entropy function).
Example ¶
dict, err := os.Open("/usr/share/dict/words") if err != nil { log.Fatal(err) } password, _, err := Diceware(dict, 5, "") if err != nil { log.Fatal(err) } fmt.Printf("Generated password: %q\n", password)
Output:
Types ¶
type CharSet ¶
type CharSet uint8
CharSet represents the set of printable ASCII characters. The maximum number of characters is 95. All printable characters are available in the continuous range of [32, 126].
const ( // Bitmask flags for creating a permutation of characters sets. SetLower CharSet = 1 << iota // Lower case letters [a-z] SetUpper // Upper case letters [A-Z] SetDigit // Decimal digits [0-9] SetPunct // Punctuation chars [!"#%&'()*,-./:;?@[\]_{}] SetSymbol // Symbolic chars [$+<=>^`|~] SetSpace // White space char SetComplete CharSet = (1 << iota) - 1 // Set of all printable chars )
func (CharSet) Cardinality ¶
Cardinality returns the charset Size.