Documentation
¶
Overview ¶
Package acopw provides a simple way to generate cryptographically secure random and diceware passwords, and PINs.
Index ¶
Examples ¶
Constants ¶
const DefaultDicewareLength int = 8
DefaultDicewareLength is the default length of a diceware password.
const DefaultPINLength int = 6
DefaultPINLength is the default length of a PIN.
const DefaultRandomLength int = 128
DefaultRandomLength is the default length of a random password.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Diceware ¶
type Diceware struct {
// Separator is the string used to separate words in the password.
Separator string
// Words is a list of words included in the generated password. If the list
// is empty, a default word list is used.
Words []string
// Length is the number of words to include in the generated password. If
// less than 1, it defaults to 8.
//
// It's the caller's responsibility to limit the maximum length to prevent
// memory exhaustion via large length values.
Length int
// Capitalize indicates whether a random word should be capitalized.
Capitalize bool
// contains filtered or unexported fields
}
Diceware is a policy for generating ChaCha8-based cryptographically strong diceware passwords. Instances are not safe for concurrent use.
func (*Diceware) Generate ¶
Generate returns a cryptographically strong diceware password for the policy. It panics if it can't get entropy from the source of randomness.
Example ¶
// Define password policy.
password := acopw.Diceware{
Length: 7, // Use 7 words.
Capitalize: true, // Capitalize the first letter of a random word.
}
// Generate and print a random diceware password. Use os.Stdout in the real
// world.
if _, err := fmt.Fprintln(os.Stderr, password.Generate()); err != nil {
log.Fatal(err)
}
type PIN ¶
type PIN struct {
// Length is the length of the generated PIN. If less than 1, it defaults to
// 6.
//
// It's the caller's responsibility to limit the maximum length to prevent
// memory exhaustion via large length values.
Length int
// contains filtered or unexported fields
}
PIN is a policy for generating ChaCha8-based cryptographically strong random PINs. Instances are not safe for concurrent use.
func (*PIN) Generate ¶
Generate returns a cryptographically strong PIN for the policy. It panics if it can't get entropy from the source of randomness.
Example ¶
// Define your PIN policy.
pin := acopw.PIN{
Length: 6, // Generate a 6 digit PIN.
}
// Generate and print a random PIN. Use os.Stdout in the real world.
if _, err := fmt.Fprintln(os.Stderr, pin.Generate()); err != nil {
log.Fatal(err)
}
type Random ¶
type Random struct {
// ExcludedCharset is a list of characters that should not be included in
// the generated password.
ExcludedCharset []string
// Length is the length of the password. If less than 1, it defaults to 128.
//
// It's the caller's responsibility to limit the maximum length to prevent
// memory exhaustion via large length values.
Length int
// UseLower, UseUpper, UseNumbers, and UseSymbols specify whether or not to
// use the corresponding character class in the generated password.
//
// If none of these are true, it defaults to true for all four.
UseLower bool
UseUpper bool
UseNumbers bool
UseSymbols bool
// contains filtered or unexported fields
}
Random is a policy for generating ChaCha8-based cryptographically strong random passwords. Instances are not safe for concurrent use.
func (*Random) Generate ¶
Generate returns a cryptographically strong random password for the policy. It panics if it can't get entropy from the source of randomness or if the internally generated character set is empty.
Example ¶
// Define password policy.
password := acopw.Random{
ExcludedCharset: []string{
" ", // Exclude spaces
"&", // Exclude ampersands
},
Length: 64, // Generate a 64 character password
UseLower: true, // Use lowercase letters
UseUpper: true, // Use uppercase letters
UseSymbols: true, // Use symbols
}
// Generate and print a random password. Use os.Stdout in the real world.
if _, err := fmt.Fprintln(os.Stderr, password.Generate()); err != nil {
log.Fatal(err)
}