Documentation
¶
Index ¶
- Constants
- Variables
- type Generator
- func (g *Generator) ExactDigits(N int) *Generator
- func (g *Generator) ExactLower(N int) *Generator
- func (g *Generator) ExactSymbols(N int) *Generator
- func (g *Generator) ExactUpper(N int) *Generator
- func (g *Generator) Generate(length int) (string, error)
- func (g *Generator) NoAmbiguousCharacters() *Generator
- func (g *Generator) RequireDigits(N int) *Generator
- func (g *Generator) RequireLower(N int) *Generator
- func (g *Generator) RequireSymbols(N int) *Generator
- func (g *Generator) RequireUpper(N int) *Generator
- func (g *Generator) WithDigits() *Generator
- func (g *Generator) WithLower() *Generator
- func (g *Generator) WithSymbols() *Generator
- func (g *Generator) WithUpper() *Generator
Examples ¶
Constants ¶
const ( // LowerLetters is the list of lowercase letters. LowerLetters = "abcdefghijklmnopqrstuvwxyz" // UpperLetters is the list of uppercase letters. UpperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // Digits is the list of permitted digits. Digits = "0123456789" // Symbols is the list of symbols. Symbols = "~!@#$%^&*()_+-={}[]" // LowerLettersNoAmbig is the list of lowercase letters. LowerLettersNoAmbig = "abcdefghjkmnpqrstuvwxyz" // UpperLettersNoAmbig is the list of uppercase letters. UpperLettersNoAmbig = "ABCDEFGHJKMNPQRSTUVWXYZ" // DigitsNoAmbig is the list of permitted digits. DigitsNoAmbig = "23456789" // SymbolsNoAmbig is the list of symbols. SymbolsNoAmbig = "~!@#$%^&*()_+-={}[]" )
Variables ¶
var ( // ErrExceedsTotalLength is the error returned when the number of required // elements is greater then the length of the requestd password ErrExceedsTotalLength = errors.New("the number of required elements exceeds requested password length") // ErrNoCharactersSpecified is the error returned when a generator is called // without any characters specified ErrNoCharactersSpecified = errors.New("no characters specified in generator") )
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is the stateful generator which can be used to customize the list of letters, digits, and/or symbols.
func (*Generator) ExactDigits ¶
ExactDigits guarantees that there are exactly N digits in the generated password.
func (*Generator) ExactLower ¶
ExactLower guarantees that there are exactly N lower case letters in the generated password.
func (*Generator) ExactSymbols ¶
ExactSymbols guarantees that there are exactly N symbols in the generated password.
func (*Generator) ExactUpper ¶
ExactUpper guarantees that there are exactly N upper case letters in the generated password.
Example ¶
pass, err := NewGenerator().ExactUpper(3).WithLower().Generate(8)
if err != nil {
log.Fatal(err)
}
log.Print(pass)
func (*Generator) Generate ¶
Generate will generate a password at the specified length as configured.
Example ¶
pass, err := NewGenerator().WithUpper().WithLower().WithDigits().WithLower().Generate(8)
if err != nil {
log.Fatal(err)
}
log.Print(pass)
func (*Generator) NoAmbiguousCharacters ¶
NoAmbiguousCharacters ensures no ambiguous characters will be in the password.
Example ¶
pass, err := NewGenerator().NoAmbiguousCharacters().WithUpper().WithLower().WithDigits().WithSymbols().Generate(16)
if err != nil {
log.Fatal(err)
}
log.Print(pass)
func (*Generator) RequireDigits ¶
RequireDigits guarantees that at least N number of digits will be in the generated password.
func (*Generator) RequireLower ¶
RequireLower guarantees that at least N number of lower case letters will be in the generated password.
func (*Generator) RequireSymbols ¶
RequireSymbols guarantees that at least N number of symbols will be in the generated password.
func (*Generator) RequireUpper ¶
RequireUpper guarantees that at least N number of upper case letters will be in the generated password.
Example ¶
pass, err := NewGenerator().RequireUpper(3).WithLower().WithDigits().WithSymbols().Generate(8)
if err != nil {
log.Fatal(err)
}
log.Print(pass)
func (*Generator) WithDigits ¶
WithDigits adds digits to the password pool. Does not guarantee digits will be present in the generated password.
func (*Generator) WithLower ¶
WithLower adds lower case letters to the password pool. Does not guarantee lower case letters will be present in the generated password.
func (*Generator) WithSymbols ¶
WithSymbols adds symbols to the password pool. Does not guarantee symbols will be present in the generated password.