Documentation ¶
Overview ¶
Package pwgen implements multiple popular password generate algorithms. It supports creating classic cryptic passwords with different character classes as well as more recent memorable approaches.
Some methods try to ensure certain requirements are met and can be very slow.
Index ¶
- Constants
- Variables
- func GenerateExternal(pwlen int) (string, error)
- func GenerateMemorablePassword(minLength int, symbols bool, capitals bool) string
- func GeneratePassword(length int, symbols bool) string
- func GeneratePasswordCharset(length int, chars string) string
- func GeneratePasswordCharsetCheck(length int, chars string) string
- func GeneratePasswordWithAllClasses(length int, symbols bool) (string, error)
- func Prune(in string, cutset string) string
- type Cryptic
Examples ¶
Constants ¶
const ( Digits = "0123456789" Upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Lower = "abcdefghijklmnopqrstuvwxyz" Syms = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" Ambiq = "0ODQ1IlB8G6S5Z2" // CharAlpha is the class of letters. CharAlpha = Upper + Lower // CharAlphaNum is the class of alpha-numeric characters. CharAlphaNum = Digits + Upper + Lower // CharAll is the class of all characters. CharAll = Digits + Upper + Lower + Syms )
Character classes.
Variables ¶
var ( // ErrNoExternal is returned when no external generator is set. ErrNoExternal = fmt.Errorf("no external generator") // ErrNoCommand is returned when no command is set. ErrNoCommand = fmt.Errorf("no command") )
var ErrCrypticInvalid = fmt.Errorf("password does not satisfy all validators")
ErrCrypticInvalid is returned when a password is invalid.
var ErrMaxTries = fmt.Errorf("maximum tries exceeded")
ErrMaxTries is returned when the maximum number of tries is reached.
Functions ¶
func GenerateExternal ¶
GenerateExternal will invoke an external password generator, if set, and return it's output.
func GenerateMemorablePassword ¶
GenerateMemorablePassword will generate a memorable password with a minimum length.
Example ¶
fmt.Println(GenerateMemorablePassword(12, false, false))
Output:
func GeneratePassword ¶
GeneratePassword generates a random, hard to remember password.
func GeneratePasswordCharset ¶
GeneratePasswordCharset generates a random password from a given set of characters.
func GeneratePasswordCharsetCheck ¶
GeneratePasswordCharsetCheck generates a random password from a given set of characters and validates the generated password with crunchy.
func GeneratePasswordWithAllClasses ¶
GeneratePasswordWithAllClasses tries to enforce a password which contains all character classes instead of only enabling them. This is especially useful for broken (corporate) password policies that mandate the use of certain character classes for no good reason.
Types ¶
type Cryptic ¶
Cryptic is a generator for hard-to-remember passwords as required by (too) many sites. Prefer memorable or xkcd-style passwords, if possible.
func NewCryptic ¶
NewCryptic creates a new generator with sane defaults.
func NewCrypticForDomain ¶
NewCrypticForDomain tries to look up password rules for the given domain or uses the default generator.
func NewCrypticWithAllClasses ¶
NewCrypticWithAllClasses returns a password generator that generates passwords containing all available character classes.
func NewCrypticWithCrunchy ¶
NewCrypticWithCrunchy returns a password generators that only returns a password if it's successfully validated with crunchy.