Documentation ¶
Overview ¶
Package password provides a library for generating random passwords using the crypto/rand package.
Index ¶
Constants ¶
const ( // Lowercase is the default list of lowercase letters. Lowercase = "abcdefghijklmnopqrstuvwxyz" // Uppercase is the default list of uppercase letters. Uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // Digits is the default list of permitted digits. Digits = "0123456789" // Symbols is the default list of symbols. Symbols = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" )
Variables ¶
var ( // ErrNegativeCharNum error is returned when a negative number of character types is requested. // E.g. impossible to return password with -1 total lowercase letters. ErrNegativeCharNum = errors.New("password with negative number of specific character types is impossible") // ErrTypeExceedsAvailable error is returned when a non-zero number of characters // of specific type is requested but the character set for that type is empty ErrTypeExceedsAvailable = errors.New("non-zero number of character type requested but character set is empty") // ErrLengthEmptyGenerator error is returned when a password of specific length is requested // but the generator does not have any characters, therefore no password can be generated ErrLengthEmptyGenerator = errors.New("password of length requested but generator character set is empty") // ErrNegativeLength error is returned when a password of negative length is requested ErrNegativeLength = errors.New("password with negative length is not possible") )
Functions ¶
func Generate ¶
Generate is the package shortcut for Generator.Generate. It uses the default character set to generate a cryptographically secure random password.
func GenerateLength ¶
GenerateLength is the package shortcut for Generator.GenerateLength. It uses the default character set to generate a cryptographically secure random password.
Types ¶
type CharSet ¶
CharSet is used for specifying a custom character set which will be used for creating a password generator.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is used for the generating of a cryptographically secure password with a initialized character set.
func NewGenerator ¶
NewGenerator creates a new Generator from the specified character set. If zero value (nil) is provided then default values are used. Otherwise, the values in the CharSet are used.