From a52221bde8cece90f36b0f4bebc3ddad48afd2d5 Mon Sep 17 00:00:00 2001 From: foswret Date: Sun, 22 Jun 2025 15:05:58 -0500 Subject: added help text and option to generate using words --- README.md | 1 + main.c | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7b9e339..9f43876 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # SPWDG ![Key illustration, coutesy of Wikimedia Commons](https://upload.wikimedia.org/wikipedia/commons/e/e9/JapanHomes141_KEY_TO_KURA_%2C_AND_BUNCH_OF_KEYS.jpg) + This is a simple password generator written in C. All randomness is produced by the [libsodium](https://github.com/jedisct1/libsodium) library. ## Dependencies diff --git a/main.c b/main.c index 66bb64e..7842ce8 100644 --- a/main.c +++ b/main.c @@ -49,26 +49,34 @@ int main (int argc, char **argv) { FILE *words; int index; - int f_flag = 0; + int w_flag = 0; int c; opterr = 0; char character_set[28] = "!@#$%^&*()_-+={}[]|~`<,>.?:;"; char letter_set[26] = "abcdefghijklmnopqrstuvwxyz"; - while ((c = getopt (argc, argv, "n")) != -1) + while ((c = getopt (argc, argv, "wh")) != -1) switch(c) { - case 'n': + case 'w': + w_flag = 1; + break; + case 'h': + printf("usage: spwdg [options]\n" + "-h shows this help text\n" + "-w generates passwords using words\n"); + return 0; case '?': if (optopt == 'c') fprintf (stderr, "Option -%c requires an argument.\n", optopt); else if (isprint (optopt)) - fprintf (stderr, "Unknown option '-%c',\n", optopt); + fprintf (stderr, "Unknown option '-%c'.\n", optopt); else - fprintf (stderr, "Unknown option character '\\x%x.\n", optopt); + fprintf(stderr,"Unknown option character '\\x%x'.\n", optopt); return 1; default: abort(); + } if (sodium_init() < 0) return 1; @@ -81,7 +89,7 @@ int main (int argc, char **argv) { temp[1] = '\0'; // Makes the array a string r = randombytes_uniform(line_total + 1); // Generates random line number to use for string - + while ((a = getc(words)) != EOF) { int i; temp[0] = a; @@ -94,12 +102,14 @@ int main (int argc, char **argv) { randomize_case(str); generate_integers(); - generate_characters(letter_set); - // printf("%s", str); + if (w_flag == 1) { + printf("%s", str); + } + else { + generate_characters(letter_set); + } generate_characters(character_set); - printf("\n"); - fseek(words, 0, SEEK_SET); // Reset pointer to beginning of file // fclose(words); } -- cgit v1.2.3