Documentation ¶
Overview ¶
Package passgen allows for creating passwords and passphrases. Custom generators can be created to allow easy, full control of the types of passwords and passphrases generated
Index ¶
- func GetAlphaLowerPassword(min, max int) (string, error)
- func GetAlphaNumericPassword(min, max int) (string, error)
- func GetAlphaPassword(min, max int) (string, error)
- func GetAlphaUpperPassword(min, max int) (string, error)
- func GetNumericPassword(min, max int) (string, error)
- func GetSecurePassword(min, max int) (string, error)
- func GetXKCDPassphrase(numWords int) (string, error)
- type PassphraseGenerator
- type PasswordGenerator
- func GetAlphaLowerPasswordGenerator() *PasswordGenerator
- func GetAlphaNumericPasswordGenerator() *PasswordGenerator
- func GetAlphaPasswordGenerator() *PasswordGenerator
- func GetAlphaUpperPasswordGenerator() *PasswordGenerator
- func GetNumericPasswordGenerator() *PasswordGenerator
- func GetSecurePasswordGenerator() *PasswordGenerator
- func NewPasswordGenerator(start byte, size int) *PasswordGenerator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAlphaLowerPassword ¶
Get a lowercase alphabetic password between min and max characters long
Example ¶
p, err := GetAlphaLowerPassword(14, 20) if err != nil { //handle error } fmt.Println(p)
Output:
func GetAlphaNumericPassword ¶
Get an alphanumeric password between min and max characters long
Example ¶
p, err := GetAlphaNumericPassword(14, 20) if err != nil { //handle error } fmt.Println(p)
Output:
func GetAlphaPassword ¶
Get an alphabetic password between min and max characters long
func GetAlphaUpperPassword ¶
Get an uppercase alphabetic password between min and max characters long
Example ¶
p, err := GetAlphaUpperPassword(14, 20) if err != nil { //handle error } fmt.Println(p)
Output:
func GetNumericPassword ¶
Get a numeric password between min and max characters long
Example ¶
p, err := GetNumericPassword(14, 20) if err != nil { //handle error } fmt.Println(p)
Output:
func GetSecurePassword ¶
Get a secure password between min and max characters long
Example ¶
p, err := GetSecurePassword(14, 20) if err != nil { //handle error } fmt.Println(p)
Output:
func GetXKCDPassphrase ¶
Quickly get a Passphrase according to XKCD example(http://xkcd.com/936/)
Example ¶
p, err := GetXKCDPassphrase(4) if err != nil { //handle error } fmt.Println(p)
Output:
Types ¶
type PassphraseGenerator ¶
type PassphraseGenerator struct { // Path of the Dictionary file to extract words from DictionaryFile string // Minimumum and Maximum word lengths of words that should be allowed in the passphrase MinWordLength, MaxWordLength int // contains filtered or unexported fields }
Passphrase Generator is used to generate secure passphrases Can be reused to generate as many sequential passphrases as desired
Example ¶
// Can use any PassphraseGenerator - provided or Custom gen, err := GetXKCDPassphraseGenerator() if err != nil { // Handle error } for i := 0; i < 5; i++ { p := gen.GeneratePassphrase(4) fmt.Println(p) }
Output:
func GetXKCDPassphraseGenerator ¶
func GetXKCDPassphraseGenerator() (*PassphraseGenerator, error)
Get a Passphrase Generator that exceeds the XKCD example (http://xkcd.com/936/). Creates a Passphrase Generator that chooses 4 words of between 4 to 10 characters long
func NewPassphraseGenerator ¶
func NewPassphraseGenerator(dictFile string, min, max int) (*PassphraseGenerator, error)
Create a new Passphrase Generator. Use "internal" for the dictfile to use an internal list of words
Example ¶
// This example will create a passphrase generator that will use 6 short words, 2 to 4 letter words, from the internal dictionary gen, err := NewPassphraseGenerator("internal", 2, 4) if err != nil { // Handle error } for i := 0; i < 5; i++ { p := gen.GeneratePassphrase(6) fmt.Println(p) }
Output:
Example (DictionaryFile) ¶
// This example will create a passphrase generator that will use a custom dictionary file for finding words gen, err := NewPassphraseGenerator("path/to/dictionary", 4, 8) if err != nil { // Handle error } for i := 0; i < 5; i++ { p := gen.GeneratePassphrase(4) fmt.Println(p) }
Output:
func (*PassphraseGenerator) GeneratePassphrase ¶
func (p *PassphraseGenerator) GeneratePassphrase(numWords int) string
Generate a Passphrase using the configuration options of the Passphrase Generator
type PasswordGenerator ¶
type PasswordGenerator struct { // The ASCII Character to start pulling allowable password characters at CharStart byte // The number of Characters to be used for the password space CharLen int // Function to map a number to the ASCII character that should represent it Func func(i uint32) byte // contains filtered or unexported fields }
Password Generator is used to generate passwords according to it's settings/properties. The generator can indefinitely be used to generate passwords.
Example ¶
// Can use any PasswordGenerator - In this example, a SecurePasswordGenerator gen := GetSecurePasswordGenerator() for i := 0; i < 5; i++ { p, err := gen.GeneratePassword(14, 20) if err != nil { //handle error } fmt.Println(p) }
Output:
func GetAlphaLowerPasswordGenerator ¶
func GetAlphaLowerPasswordGenerator() *PasswordGenerator
Get a Password Generator that will only allow lower case alphabetic characters. (a-z) - 26 characters
func GetAlphaNumericPasswordGenerator ¶
func GetAlphaNumericPasswordGenerator() *PasswordGenerator
Get a Password Generator that will only allow alphanumeric characters. (A-Za-z0-9) - 62 characters
func GetAlphaPasswordGenerator ¶
func GetAlphaPasswordGenerator() *PasswordGenerator
Get a Password Generator that will only allow alphabetic characters. (A-Za-z) - 52 characters
func GetAlphaUpperPasswordGenerator ¶
func GetAlphaUpperPasswordGenerator() *PasswordGenerator
Get a Password Generator that will only allow upper case alphabetic characters. (A-Z) - 26 characters
func GetNumericPasswordGenerator ¶
func GetNumericPasswordGenerator() *PasswordGenerator
Get a Password Generator that will only allow numeric characters. (0-9) - 10 characters
func GetSecurePasswordGenerator ¶
func GetSecurePasswordGenerator() *PasswordGenerator
Get a Password Generator that will allow ASCII x20-x7E - 95 characters
func NewPasswordGenerator ¶
func NewPasswordGenerator(start byte, size int) *PasswordGenerator
Get a new Password Generator designed to start at the given starting character and use the given character space
Example ¶
// Make a password generator that will only return passwords containing chars a-e gen := NewPasswordGenerator('a', 5) // Can now use the generator to create as many passwords as needed for i := 0; i < 5; i++ { p, err := gen.GeneratePassword(14, 20) if err != nil { //handle error } fmt.Println(p) }
Output:
Example (Custom) ¶
// Make a password generator that will only return passwords containing chars of even numbers gen := NewPasswordGenerator('0', 5) gen.Func = func(i uint32) byte { diff := i * 2 return gen.CharStart + byte(diff) } // Can now use the generator to create as many passwords as needed for i := 0; i < 5; i++ { p, err := gen.GeneratePassword(14, 20) if err != nil { //handle error } fmt.Println(p) }
Output:
func (*PasswordGenerator) GeneratePassword ¶
func (p *PasswordGenerator) GeneratePassword(min, max int) (string, error)
Use the generator to create a password in between the given lengths
func (*PasswordGenerator) GetMaxLength ¶
func (p *PasswordGenerator) GetMaxLength(n int) int
Get the maximum length in bytes that the generated password might need