aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2021-12-01 00:05:16 +1100
committerNicholas Tay <nick@windblume.net>2021-12-01 00:05:16 +1100
commit68315feb59829570872ab5a0a54d6d12ad6b4d84 (patch)
tree489e4558e9a7c3998b7217c9cb17e3727f8c05c8
parentd62b1765f6a0fddff02c837e797bb54da920aaf5 (diff)
downloadpassgen-68315feb59829570872ab5a0a54d6d12ad6b4d84.tar.gz
passgen-68315feb59829570872ab5a0a54d6d12ad6b4d84.tar.bz2
passgen-68315feb59829570872ab5a0a54d6d12ad6b4d84.zip
Take in triplet/specials/numbers arguments
-rw-r--r--passgen.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/passgen.c b/passgen.c
index fd509d2..202809b 100644
--- a/passgen.c
+++ b/passgen.c
@@ -12,11 +12,36 @@
#define NUMBERS "1234567890"
#define SYMBOLS "@#$%^&*_-+=()[]{}"
-int main()
+int main(int argc, char *argv[])
{
char *grammar = DEFAULT_GRAMMAR;
int grammar_size = sizeof(DEFAULT_GRAMMAR)-1;
-
+
+ if (argc == 4) {
+ // 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]);
+
+ if (triplets < 1) {
+ printf("ERROR: Cannot have less than one triplet.");
+ return 1;
+ }
+
+ grammar_size = triplets * 3 + specials + numbers;
+ grammar = malloc(grammar_size + 1);
+ grammar[grammar_size] = 0;
+
+ memcpy(grammar, "Cvc", 3);
+ for (int i = 1; i < triplets; ++i)
+ memcpy(grammar + (i * 3), "cvc", 3);
+
+ memset(grammar + (triplets * 3), '!', specials);
+ memset(grammar + (triplets * 3) + specials, '#', numbers);
+ //printf("Custom: %s\n", grammar);
+ }
+
char password[grammar_size];
// seed RNG; this isn't very good, but it's enough (for now)
@@ -49,6 +74,8 @@ int main()
setClass(NUMBERS);
default:
printf("ERROR: Invalid grammar character '%c'.\n", c);
+ if (grammar != (char*)DEFAULT_GRAMMAR)
+ free(grammar);
return 1;
}
@@ -57,6 +84,9 @@ int main()
} while (i != 0 && password[i] == password[i-1]);
}
+ if (grammar != (char*)DEFAULT_GRAMMAR)
+ free(grammar);
+
printf("%s\n", password);
return 0;