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:
2021-11-15 01:18:39 +01:00
parent 0a7046d45c
commit e81544ff5f
2 changed files with 32 additions and 2 deletions

View File

@ -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);