c,python: Add the 'b' pattern for base64 encoded strings
Change the default pattern to use a short base64 string at the end. This increses the used bits to generate a password from 65 to 73.
This commit is contained in:
@ -21,13 +21,18 @@
|
||||
/*
|
||||
* The default pattern used for password generation
|
||||
*/
|
||||
#define PASSGENY_DEFAULT_PATTERN "^6p^6p^6ps2p100d"
|
||||
#define PASSGENY_DEFAULT_PATTERN "^6p^6p^6ps3bd"
|
||||
|
||||
/*
|
||||
* List of special characters (order is important)
|
||||
*/
|
||||
#define PASSGENY_SPECIAL " +-./=_"
|
||||
|
||||
/*
|
||||
* base64 characters
|
||||
*/
|
||||
#define PASSGENY_BASE64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
|
||||
/*
|
||||
* Argon2 parameters
|
||||
*/
|
||||
@ -235,6 +240,21 @@ bool passgeny_generate(
|
||||
|
||||
passgeny_gen_str(cword, clen + 1, "0123456789abcdef", &bh);
|
||||
}
|
||||
else if (passgeny_patmatch(&ppat, "([0-9]*)b", popt, sizeof(popt)))
|
||||
{
|
||||
size_t clen = atoi(popt);
|
||||
if (clen >= sizeof(cword))
|
||||
{
|
||||
fprintf(stderr, "Invalid base64 string length: %zd\n", clen);
|
||||
return false;
|
||||
}
|
||||
else if (clen == 0)
|
||||
{
|
||||
clen = 1;
|
||||
}
|
||||
|
||||
passgeny_gen_str(cword, clen + 1, PASSGENY_BASE64, &bh);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error parsing pattern at: %s\n", ppat);
|
||||
|
||||
@ -10,11 +10,14 @@ from . import bhash, phogen
|
||||
#
|
||||
# WARNING: Changing any of the parameters below will affect password generation
|
||||
#
|
||||
PASSGENY_DEFAULT_PATTERN = "^6p^6p^6ps2p100d"
|
||||
PASSGENY_DEFAULT_PATTERN = "^6p^6p^6ps3b10d"
|
||||
|
||||
# List of special characters
|
||||
PASSGENY_SPECIAL = " +-./=_"
|
||||
|
||||
# List of base64 characters
|
||||
PASSGENY_BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
|
||||
# Default SALT to use; this cannot be random since passgeny must
|
||||
# generate predictable passwords
|
||||
PASSGENY_SALT_DEFAULT = b"Passgeny v1"
|
||||
@ -93,6 +96,12 @@ class Passgeny:
|
||||
x += "{:x}".format(bh.modulo(16))
|
||||
return x
|
||||
|
||||
def gen_base64(match):
|
||||
blen = 1 if match[1] == "" else int(match[1])
|
||||
b = ""
|
||||
for l in range(blen):
|
||||
b += PASSGENY_BASE64[bh.modulo(len(PASSGENY_BASE64))]
|
||||
return b
|
||||
|
||||
def gen_capitalize(match):
|
||||
nonlocal flags
|
||||
@ -104,6 +113,7 @@ class Passgeny:
|
||||
[ '([0-9]*)s', gen_special ],
|
||||
[ '([0-9]+)d', gen_decimal ],
|
||||
[ '([0-9]+)x', gen_hexstr ],
|
||||
[ '([0-9]+)b', gen_base64 ],
|
||||
[ '\^', gen_capitalize ],
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user