diff options
author | Nicholas Tay <nick@windblume.net> | 2022-01-05 23:53:38 +1100 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2022-01-05 23:53:38 +1100 |
commit | 72a346dc04575e62dacf63dad8d36b7770ba5561 (patch) | |
tree | 4477beca305d9f1858ae3cecc807f6a8c4d34573 /passgen.c | |
parent | 4dbe5cd8903ed83614d5659d39ea98e12d197361 (diff) | |
download | passgen-72a346dc04575e62dacf63dad8d36b7770ba5561.tar.gz passgen-72a346dc04575e62dacf63dad8d36b7770ba5561.tar.bz2 passgen-72a346dc04575e62dacf63dad8d36b7770ba5561.zip |
astyle + additional comments (+ to c89 style)
https://gist.github.com/nicholastay/9eb6a455d6b17b810cd8e7bec2a5dfe7
Diffstat (limited to 'passgen.c')
-rw-r--r-- | passgen.c | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -20,25 +20,27 @@ #define CLASS(c, chars) \ - case c: \ - class = chars; \ - class_size = sizeof(chars)-1; \ - break; + case c: \ + class = chars; \ + class_size = sizeof(chars)-1; \ + break; int main(int argc, char *argv[]) { bool custom_grammar = false; char *grammar = DEFAULT_GRAMMAR; - int grammar_size = sizeof(DEFAULT_GRAMMAR)-1; + int grammar_size = sizeof(DEFAULT_GRAMMAR) - 1; if (argc == 2) { - // Take first argument as the grammar + /* Take first argument as the grammar */ grammar = argv[1]; grammar_size = strlen(grammar); } else if (argc == 4) { - // Take arguments as triplets, specials, numbers - // atoi might be scuffed but so be it (it just goes = 0 if invalid input) + /* + * Take arguments as triplets, specials, numbers + * atoi might be scuffed but so be it (it just goes = 0 if invalid input) + */ int triplets = atoi(argv[1]); int specials = atoi(argv[2]); int numbers = atoi(argv[3]); @@ -73,7 +75,17 @@ int main(int argc, char *argv[]) password[grammar_size] = 0; #ifndef __linux__ - // seed RNG; this isn't very good, but it's enough(?) + /* + * TODO: seed better RNG + * this isn't very good, but it's enough(?) for now + * + * on linux we use the `getrandom` api which is supposedly + * what crypto uses to generate. potentially on win we + * can use the crypto thing (but it's more complicated + * to invoke). + * + * anything else we could use on posix systems? + */ srand(time(NULL) + getpid() % 420 - 69); #endif @@ -106,7 +118,7 @@ int main(int argc, char *argv[]) long r = rand(); #endif password[i] = class[r % class_size] - (caps ? 'a' - 'A' : 0); - } while (i != 0 && password[i] == password[i-1]); + } while (i != 0 && password[i] == password[i - 1]); } if (custom_grammar) |