Documentation ¶
Overview ¶
Package passit provides a password generation toolkit. It features a variety of different password generators from charsets to regular expressions and emoji.
All generators implement Generator. Once a suitable Generator has been constructed, passwords can be generated by calling the Generator.Password method. All generators in this package are deterministic unless otherwise noted.
Most generators only generate a single of something, be it a rune, ASCII character or word. For generating longer passwords use Repeat or RandomRepeat, possibly with Join or Alternate. In this way the various generators can be composed to generator arbitrarily long and complex passwords, or short and simple passwords as is needed.
For generating random passwords, Generator.Password should be called with crypto/rand.Reader. Avoid using poor quality sources of randomness like math/rand.
For generating deterministic passwords, Generator.Password should be called with a deterministic stream that should be indistinguishable from a random string of the same length. Care must be taken when using deterministic password generation as the generated password is only ever as good as the provided source of randomness.
Note: Wrapping the io.Reader with bufio.NewReader (if it doesn't already implement io.ByteReader) will greatly improve the performance of the generators.
Index ¶
- Variables
- type Generator
- func Alternate(gens ...Generator) Generator
- func Ascii85(count int) Generator
- func Base32(count int) Generator
- func Base32Hex(count int) Generator
- func Base64(count int) Generator
- func Base64URL(count int) Generator
- func FromCharset(charset string) Generator
- func FromRangeTable(tab *unicode.RangeTable) Generator
- func FromSlice(list ...string) Generator
- func HexLower(count int) Generator
- func HexUpper(count int) Generator
- func Join(sep string, gens ...Generator) Generator
- func LowerCase(gen Generator) Generator
- func ParseRegexp(pattern string, flags syntax.Flags) (Generator, error)
- func RandomRepeat(gen Generator, sep string, min, max int) Generator
- func RejectionSample(gen Generator, condition func(string) bool) Generator
- func Repeat(gen Generator, sep string, count int) Generator
- func RepeatGen(gen, sep Generator, count int) Generator
- func String(s string) Generator
- func TitleCase(gen Generator, t language.Tag) Generator
- func Transform(gen Generator, fn func(string) string) Generator
- func UpperCase(gen Generator) Generator
- type GeneratorFunc
- type RegexpParser
- type SpecialCaptureFactory
- type SpectreTemplate
Constants ¶
This section is empty.
Variables ¶
var EmojiLatest = Emoji15
EmojiLatest is an alias for the latest supported emoji list.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator interface { // Password returns a randomly generated password using r as the source of // randomness. // // The returned password may or may not be deterministic with respect to r. // All generators in this package are deterministic unless otherwise noted. // // The output of r should be indistinguishable from a random string of the // same length. This is a property of a good CSPRNG. Fundamentally the // strength of the generated password is only as good as the provided source // of randomness. // // r should implement the io.ByteReader interface for improved performance. Password(r io.Reader) (string, error) }
Generator is an interface for generating passwords.
var ASCIIGraphic Generator = &asciiGenerator{"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"}
ASCIIGraphic is a Generator that returns a random ASCII graphic character excluding space. The set of characters is
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
This is ASCII characters from the Unicode L/Letter, M/Mark, N/Number, P/Punctuation and S/Symbol categories.
var ASCIINoLetters Generator = &asciiGenerator{"!\"#$%&'()*+,-./0123456789:;<=>?@[\\]^_`{|}~"}
ASCIINoLetters is a Generator that returns a random ASCII number, punctuation or symbol character. The set of characters is
!"#$%&'()*+,-./0123456789:;<=>?@[\]^_`{|}~
This is ASCII characters from the Unicode N/Number, P/Punctuation and S/Symbol categories, or alternatively ASCII graphic characters that are not letters or spaces.
var ASCIINoLettersNumbers Generator = &asciiGenerator{"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"}
ASCIINoLettersNumbers is a Generator that returns a random ASCII punctuation or symbol character. The set of characters is
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
This is ASCII characters from the Unicode P/Punctuation and S/Symbol categories, or alternatively ASCII graphic characters that are not letters, numbers or spaces.
var Digit Generator = &asciiGenerator{"0123456789"}
Digit is a Generator that returns a random numeric digit.
var EFFLargeWordlist Generator = &embeddedGenerator{raw: &wordlist.EFFLargeWordlist}
EFFLargeWordlist is a Generator that returns a random word from the EFF Large Wordlist for Passphrases (eff_large_wordlist.txt).
It contains 7,776 words and has 12.925 bits of entropy per word.
This wordlist is licensed by the Electronic Frontier Foundation under a CC BY 3.0 US license.
var EFFShortWordlist1 Generator = &embeddedGenerator{raw: &wordlist.EFFShortWordlist1}
EFFShortWordlist1 is a Generator that returns a random word from the EFF Short Wordlist for Passphrases #1 (eff_short_wordlist_1.txt).
It contains 1,296 words and has 10.340 bits of entropy per word.
This wordlist is licensed by the Electronic Frontier Foundation under a CC BY 3.0 US license.
var EFFShortWordlist2 Generator = &embeddedGenerator{raw: &wordlist.EFFShortWordlist2}
EFFShortWordlist2 is a Generator that returns a random word from the EFF Short Wordlist for Passphrases #2 (eff_short_wordlist_2_0.txt).
It contains 1,296 words and has 10.340 bits of entropy per word.
This wordlist is licensed by the Electronic Frontier Foundation under a CC BY 3.0 US license.
Emoji13 is a Generator that returns a random fully-qualified emoji from the Unicode 13.0 emoji list.
Emoji15 is a Generator that returns a random fully-qualified emoji from the Unicode 15.0 emoji list.
var Empty Generator = fixedString("")
Empty is a Generator that always returns an empty string.
var Hyphen Generator = fixedString("-")
Hyphen is a Generator that always returns a fixed ASCII hyphen-minus.
var LatinLower Generator = &asciiGenerator{"abcdefghijklmnopqrstuvwxyz"}
LatinLower is a Generator that returns a random lowercase character from the latin alphabet.
var LatinLowerDigit Generator = &asciiGenerator{"abcdefghijklmnopqrstuvwxyz0123456789"}
LatinLowerDigit is a Generator that returns a random lowercase character from the latin alphabet or a numeric digit.
var LatinMixed Generator = &asciiGenerator{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}
LatinMixed is a Generator that returns a random mixed-case characters from the latin alphabet.
var LatinMixedDigit Generator = &asciiGenerator{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"}
LatinMixedDigit is a Generator that returns a random mixed-case characters from the latin alphabet or a numeric digit.
var LatinUpper Generator = &asciiGenerator{"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}
LatinUpper is a Generator that returns a random uppercase character from the latin alphabet.
var LatinUpperDigit Generator = &asciiGenerator{"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"}
LatinUpperDigit is a Generator that returns a random uppercase character from the latin alphabet or a numeric digit.
var OrchardStreetAlpha Generator = &embeddedGenerator{raw: &wordlist.OrchardStreetAlpha}
OrchardStreetAlpha is a Generator that returns a random word from Sam Schlinkert's Orchard Street Alpha List.
It contains 1,296 words and has 10.340 bits of entropy per word. This list is uniquely decodable and can be used with or without separators.
This wordlist is licensed by Sam Schlinkert under a CC BY-SA 4.0 license.
var OrchardStreetLong Generator = &embeddedGenerator{raw: &wordlist.OrchardStreetLong}
OrchardStreetLong is a Generator that returns a random word from Sam Schlinkert's Orchard Street Long List.
It contains 17,576 words and has 14.101 bits of entropy per word. This list is uniquely decodable and can be used with or without separators.
This wordlist is licensed by Sam Schlinkert under a CC BY-SA 4.0 license.
var OrchardStreetMedium Generator = &embeddedGenerator{raw: &wordlist.OrchardStreetMedium}
OrchardStreetMedium is a Generator that returns a random word from Sam Schlinkert's Orchard Street Medium List.
It contains 8,192 words and has 13.000 bits of entropy per word. This list is uniquely decodable and can be used with or without separators.
This wordlist is licensed by Sam Schlinkert under a CC BY-SA 4.0 license.
var OrchardStreetQWERTY Generator = &embeddedGenerator{raw: &wordlist.OrchardStreetQWERTY}
OrchardStreetQWERTY is a Generator that returns a random word from Sam Schlinkert's Orchard Street QWERTY List.
It contains 1,296 words and has 10.340 bits of entropy per word. This list is uniquely decodable and can be used with or without separators.
This wordlist is licensed by Sam Schlinkert under a CC BY-SA 4.0 license.
var STS10Wordlist Generator = &embeddedGenerator{raw: &wordlist.STS10Wordlist}
STS10Wordlist is a Generator that returns a random word from Sam Schlinkert's '1Password Replacement List'.
It contains 18,208 words and has 14.152 bits of entropy per word. This list is not uniquely decodable and should only be used with separators.
This wordlist is licensed by Sam Schlinkert under a CC BY 3.0 license.
Deprecated: This list is not safe to use without separators. Use one of the other wordlists instead, like OrchardStreetLong.
var Space Generator = fixedString(" ")
Space is a Generator that always returns a fixed ASCII space.
func Alternate ¶
Alternate returns a Generator that randomly selects one of the provided Generator's to use to generate the password.
func Base32 ¶
Base32 returns a Generator that encodes count-bytes with encoding/base32.StdEncoding without padding.
func Base32Hex ¶
Base32Hex returns a Generator that encodes count-bytes with encoding/base32.HexEncoding without padding.
func Base64 ¶
Base64 returns a Generator that encodes count-bytes with encoding/base64.RawStdEncoding.
func Base64URL ¶
Base64URL returns a Generator that encodes count-bytes with encoding/base64.RawURLEncoding.
func FromCharset ¶
FromCharset returns a Generator that returns a random rune from charset.
func FromRangeTable ¶
func FromRangeTable(tab *unicode.RangeTable) Generator
FromRangeTable returns a Generator that returns a random rune from the unicode.RangeTable.
The returned Generator is only deterministic if the same unicode.RangeTable is used. Be aware that the builtin unicode.X tables are subject to change as new versions of Unicode are released and are not suitable for deterministic use.
func Join ¶
Join returns a Generator that concatenates the outputs of each Generator to create a single string. The separator string sep is placed between the outputs in the resulting string.
func LowerCase ¶
LowerCase returns a Generator that uses strings.ToLower to map all Unicode letters in the generated password to their lower case.
func ParseRegexp ¶
ParseRegexp is a shortcut for new(RegexpParser).Parse(pattern, flags).
func RandomRepeat ¶
RandomRepeat returns a Generator that concatenates the output of invoking the Generator a random number of times in [min,max] to create a single string. The separator string sep is placed between the outputs in the resulting string.
func RejectionSample ¶
RejectionSample returns a Generator that continually generates passwords with gen until condition reports true for the generated password or an error occurs.
The behaviour is unspecified if condition never reports true.
func Repeat ¶
Repeat returns a Generator that invokes the Generator count times and concatenates the output with a fixed separator.
func RepeatGen ¶
RepeatGen returns a Generator that invokes gen count times and concatenates the output with a dynamic separator produced by sep.
For instance, RepeatGen(gen, sep, 4) would be equivalent to Join("", gen, sep, gen, sep, gen, sep, gen).
func TitleCase ¶
TitleCase returns a Generator that uses golang.org/x/text/cases.Title to convert the generated password to language-specific title case.
func Transform ¶
Transform returns a Generator that converts the generated password according to the user supplied function fn.
func UpperCase ¶
UpperCase returns a Generator that uses strings.ToUpper to map all Unicode letters in the generated password to their upper case.
type GeneratorFunc ¶
The GeneratorFunc type is an adapter to allow the use of ordinary functions as password generators. If f is a function with the appropriate signature, GeneratorFunc(f) is a Generator that calls f.
type RegexpParser ¶
type RegexpParser struct {
// contains filtered or unexported fields
}
RegexpParser is a regular expressions parser that parses patterns into a Generator that generates passwords matching the parsed regexp. The zero-value is a usable parser.
func (*RegexpParser) Parse ¶
Parse parses the regexp pattern according to the flags and returns a Generator. It returns an error if the regexp is invalid. It uses regexp/syntax to parse the pattern.
All regexp features supported by regexp/syntax are supported, though some may have no effect.
It is an error to use named captures (?P<name>) except to refer to special capture factories added with SetSpecialCapture.
func (*RegexpParser) SetAnyRangeTable ¶
func (p *RegexpParser) SetAnyRangeTable(tab *unicode.RangeTable)
SetAnyRangeTable sets the unicode.RangeTable used when generating any (.) characters or when restricting character classes ([a-z]) with a user provided one. By default a subset of ASCII is used. Calling SetAnyRangeTable(nil) will reset the RegexpParser back to the default.
The regexp Generator is only deterministic if the same unicode.RangeTable is used. Be aware that the builtin unicode.X tables are subject to change as new versions of Unicode are released and are not suitable for deterministic use.
func (*RegexpParser) SetSpecialCapture ¶
func (p *RegexpParser) SetSpecialCapture(name string, factory SpecialCaptureFactory)
SetSpecialCapture adds a special capture factory to use for matching named captures. A regexp pattern such as "(?P<name>)" will invoke the factory and use the returned Generator instead of the contents of the capture. If name is "*", the factory will be used as a fallback if a named factory can't be found.
If attempting to parse the inner contents of the capture, be aware that the regexp parser may have mangled them. For instance "(?P<name>1|2)" will become "(?P<name>[1-2])", "(?P<name>z|z)" will become "(?P<name>z)" and "(?i:(?P<name>z))" will become "(?P<name>(?i:Z))".
type SpecialCaptureFactory ¶
SpecialCaptureFactory represents a special capture factory to be used with (*RegexpParser).SetSpecialCapture.
func SpecialCaptureBasic ¶
func SpecialCaptureBasic(gen Generator) SpecialCaptureFactory
SpecialCaptureBasic returns a special capture factory that doesn't accept any input and always returns the provided Generator.
func SpecialCaptureWithRepeat ¶
func SpecialCaptureWithRepeat(gen Generator, sep string) SpecialCaptureFactory
SpecialCaptureWithRepeat returns a special capture factory that parses the capture value for a count to be used with Repeat(gen, sep, count). If the capture is empty, the Generator is returned directly.
type SpectreTemplate ¶
type SpectreTemplate string
SpectreTemplate is a Generator that implements a variant of the Spectre / Master Password encoding algorithm by Maarten Billemont.
This algorithm is not compatible with any of the officially published algorithms, but it does produce passwords using the same templates that are indistinguishable from the official algorithm. Unlike that algorithm, this doesn't exhibit a modulo bias.
const ( SpectreMaximum SpectreTemplate = "anoxxxxxxxxxxxxxxxxx:axxxxxxxxxxxxxxxxxno" SpectreLong SpectreTemplate = "" /* 314-byte string literal not displayed */ SpectreMedium SpectreTemplate = "CvcnoCvc:CvcCvcno" SpectreBasic SpectreTemplate = "aaanaaan:aannaaan:aaannaaa" SpectreShort SpectreTemplate = "Cvcn" SpectrePIN SpectreTemplate = "nnnn" SpectreName SpectreTemplate = "cvccvcvcv" SpectrePhrase SpectreTemplate = "cvcc cvc cvccvcv cvc:cvc cvccvcvcv cvcv:cv cvccv cvc cvcvccv" )
These are the standard templates defined by Spectre / Master Password.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
passphrase
Command passphrase generates random passphrases using one of the embedded wordlists supported by passit.
|
Command passphrase generates random passphrases using one of the embedded wordlists supported by passit. |
twoproblems
Command twoproblems generates random passwords based on a regular expression template.
|
Command twoproblems generates random passwords based on a regular expression template. |
internal
|
|
wordlists
Package wordlists provides utility functions for working with wordlists.
|
Package wordlists provides utility functions for working with wordlists. |