2022-03-02 06:24:55 -05:00
|
|
|
|
package pwgenerator
|
|
|
|
|
|
2022-03-03 04:26:44 -05:00
|
|
|
|
// Defaults.
|
|
|
|
|
const (
|
|
|
|
|
DefCount uint = 1
|
|
|
|
|
DefMaxLen uint = 256
|
|
|
|
|
DefMinLin uint = 1
|
|
|
|
|
)
|
|
|
|
|
|
2022-03-02 06:24:55 -05:00
|
|
|
|
// Pre-defined charsets.
|
|
|
|
|
var (
|
|
|
|
|
// upper contains the characters from 0x41 to 0x5a ([A-Z]).
|
|
|
|
|
upper CharSet = CharSet{
|
|
|
|
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
|
|
|
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
|
|
|
}
|
|
|
|
|
// lower contains the characters from 0x61 to 0x7a ([a-z]).
|
|
|
|
|
lower CharSet = CharSet{
|
|
|
|
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
|
|
|
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
|
|
|
}
|
|
|
|
|
// alpha contains upper and lower.
|
|
|
|
|
alpha CharSet = append(upper, lower...)
|
|
|
|
|
// numeric contains the characters from 0x30 to 0x39 ([0-9]).
|
|
|
|
|
numeric CharSet = CharSet{
|
|
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
|
|
|
|
}
|
|
|
|
|
// alphaNumeric combines alpha and numeric. This is, by far, the most widely-supported charset.
|
|
|
|
|
alphaNumeric CharSet = append(alpha, numeric...)
|
|
|
|
|
/*
|
|
|
|
|
symbols contains the characters from:
|
|
|
|
|
0x21 to 0x2f
|
|
|
|
|
0x3a to 0x40
|
|
|
|
|
0x5b to 0x60
|
|
|
|
|
0x7b to 0x7e
|
|
|
|
|
*/
|
|
|
|
|
symbols CharSet = CharSet{
|
|
|
|
|
// 0x21 to 0x2f
|
|
|
|
|
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
|
|
|
|
|
// 0x3a to 0x40
|
|
|
|
|
':', ';', '<', '=', '>', '?', '@',
|
|
|
|
|
// 0x5b to 0x60
|
|
|
|
|
'[', '\\', ']', '^', '_', '`',
|
|
|
|
|
// 0x7b to 0x7e
|
|
|
|
|
'{', '|', '}', '~',
|
|
|
|
|
}
|
|
|
|
|
// safeAscii can be expected to support strong passwords while also be reasonably supported JUST about in every application.
|
|
|
|
|
safeAscii CharSet = append(alphaNumeric, symbols...)
|
|
|
|
|
/*
|
|
|
|
|
extendedSymbols contains the characters from 0x80 to 0xff, excluding:
|
|
|
|
|
0x81, 0x8d, 0x8f, 0x90, 0x9d, 0xa0, 0xad
|
|
|
|
|
as they have no defined ASCII mapping.
|
|
|
|
|
*/
|
|
|
|
|
extendedSymbols CharSet = CharSet{
|
|
|
|
|
'€', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ',
|
|
|
|
|
'Ž', '‘', '’', '“', '”', '•', '–', '—', '˜', '™', 'š', '›',
|
|
|
|
|
'œ', 'ž', 'Ÿ', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©',
|
|
|
|
|
'ª', '«', '¬', '®', '¯', '°', '±', '²', '³', '´', 'µ', '¶',
|
|
|
|
|
'·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â',
|
|
|
|
|
'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î',
|
|
|
|
|
'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú',
|
|
|
|
|
'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ',
|
|
|
|
|
'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò',
|
|
|
|
|
'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ',
|
|
|
|
|
}
|
|
|
|
|
// allSymbols contains all printable non-alphanumerics.
|
|
|
|
|
allSymbols CharSet = append(symbols, extendedSymbols...)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
/*
|
|
|
|
|
AmbiguousChars are visually-ambiguous characters that may be hard to visually differentiate
|
|
|
|
|
depending on the font (especially in monospace fonts).
|
|
|
|
|
|
|
|
|
|
To be specifically clear, each character is provided with its ASCII hex value.
|
|
|
|
|
If you need the decimal/octal/etc. reference instead, you can cross-reference
|
|
|
|
|
it via https://square-r00t.net/ascii.html.
|
|
|
|
|
*/
|
|
|
|
|
// TODO: finish this; left off at 0xaa.
|
|
|
|
|
AmbiguousChars []Char = []Char{
|
|
|
|
|
'`', // 0x60
|
|
|
|
|
'\'', // 0x27
|
|
|
|
|
'‘', // 0x91
|
|
|
|
|
'’', // 0x92
|
|
|
|
|
'"', // 0x22
|
|
|
|
|
'“', // 0x93
|
|
|
|
|
'”', // 0x94
|
|
|
|
|
'¨', // 0xa8
|
|
|
|
|
'*', // 0x2a
|
|
|
|
|
'•', // 0x95
|
|
|
|
|
',', // 0x2c
|
|
|
|
|
'.', // 0x2e
|
|
|
|
|
'‚', // 0x82
|
|
|
|
|
'…', // 0x85
|
|
|
|
|
'!', // 0x21
|
|
|
|
|
'¡', // 0xa1
|
|
|
|
|
'1', // 0x31
|
|
|
|
|
'I', // 0x49
|
|
|
|
|
'l', // 0x6c
|
|
|
|
|
'|', // 0x7c
|
|
|
|
|
'¦', // 0xa6
|
|
|
|
|
'c', // 0x63
|
|
|
|
|
'¢', // 0xa2
|
|
|
|
|
'0', // 0x30
|
|
|
|
|
'O', // 0x4f
|
|
|
|
|
'o', // 0x6f
|
|
|
|
|
'$', // 0x24
|
|
|
|
|
'S', // 0x53
|
|
|
|
|
's', // 0x73
|
|
|
|
|
'Š', // 0x8a
|
|
|
|
|
'š', // 0x9a
|
|
|
|
|
'§', // 0xa7
|
|
|
|
|
'-', // 0x2d
|
|
|
|
|
'_', // 0x5f
|
|
|
|
|
'–', // 0x96
|
|
|
|
|
'—', // 0x97
|
|
|
|
|
'~', // 0x7e
|
|
|
|
|
'˜', // 0x98
|
|
|
|
|
'^', // 0x5e
|
|
|
|
|
'ˆ', // 0x88
|
|
|
|
|
'%', // 0x25
|
|
|
|
|
'‰', // 0x89
|
|
|
|
|
'<', // 0x3c
|
|
|
|
|
'‹', // 0x8b
|
|
|
|
|
'>', // 0x3e
|
|
|
|
|
'›', // 0x9b
|
|
|
|
|
'Y', // 0x59
|
|
|
|
|
'Ÿ', // 0x9f
|
|
|
|
|
'¥', // 0xa5
|
|
|
|
|
'Z', // 0x5a
|
|
|
|
|
'z', // 0x7a
|
|
|
|
|
'Ž', // 0x8e
|
|
|
|
|
'ž', // 0x9e
|
|
|
|
|
'(', // 0x28
|
|
|
|
|
'[', // 0x5b
|
|
|
|
|
'{', // 0x7b
|
|
|
|
|
')', // 0x29
|
|
|
|
|
']', // 0x5d
|
|
|
|
|
'}', // 0x7d
|
|
|
|
|
}
|
|
|
|
|
)
|