diff options
author | foswret <foswret@posteo.com> | 2025-06-22 15:05:58 -0500 |
---|---|---|
committer | foswret <foswret@posteo.com> | 2025-06-22 15:05:58 -0500 |
commit | 2e84588ec83b453e9c1a667841200b7d77260621 (patch) | |
tree | 7b769ba21495a009a52c0a337151efe7da67f9ab | |
parent | 1dea63bc263ccb8f35728d41e51804d01c7cc06d (diff) |
removed un-needed comments
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | password.c | 44 |
2 files changed, 28 insertions, 31 deletions
@@ -1,13 +1,16 @@ -This is a simple password generator that I created because I was tired of thinking up of passwords. All randomness is produced by the [libsodium](https://github.com/jedisct1/libsodium) library. +# SPWDG +This is a simple password generator written in C. All randomness is produced by the [libsodium](https://github.com/jedisct1/libsodium) library. + ## Dependencies -- `make` -- `libsodium` +- gcc +- make +- libsodium ## Install -- `make` -- `sudo make install` +- make +- sudo make install ## Uninstall -- `sudo make uninstall` +- sudo make uninstall @@ -1,35 +1,34 @@ #include <sodium/randombytes.h> #include <stdio.h> -#include <stdlib.h> #include <string.h> #include <sodium.h> #include <ctype.h> //To Upper -long count_lines(FILE *File) { // Accepts file as input +long count_lines(FILE *File) { char c; long line_counter = 0; while ((c = getc(File)) != EOF) { if (c == '\n') { - line_counter++; // Increment when each line number is passed + line_counter++; } } - return(line_counter); // Return the found value + return(line_counter); } void randomize_case(char *a) { // Accepts a string as input - for (int i = 0; i < strlen(a); i++) { // Loop through the length of the string + for (int i = 0; i < strlen(a); i++) { int coin = randombytes_uniform(2); // Decide if the current character will be capitalized or lowercase if (coin == 1) { - a[i] = toupper(a[i]); // Change current character into a capital + a[i] = toupper(a[i]); } } } -void generate_integers(void) { // Generates a string of random integers +void generate_integers(void) { int length = 5; // TO-DO: Make random eventually for (int i=0; i<length; i++) { - int random = randombytes_uniform(length); // Generate random number + int random = randombytes_uniform(length); printf("%d", random); } } @@ -42,38 +41,34 @@ void generate_characters(char *set) { } int main (int argc, char **argv) { - char c; + char c, arg, str[20]; FILE *words; - long line_counter; - long line_total, r; - char str[20]; + long line_counter, line_total, r; - char character_set[28] = "!@#$%^&*()_-+={}[]|~`<,>.?:;"; // Character set used to generate random characters - if (sodium_init() < 0) return 1; // Returns an error if sodium isn't working correctly - words = fopen("word_list.txt", "r"); // Open text file + char character_set[28] = "!@#$%^&*()_-+={}[]|~`<,>.?:;"; + char letter_set[26] = "abcdefghijklmnopqrstuvwxyz"; + if (sodium_init() < 0) return 1; + words = fopen("word_list.txt", "r"); - line_total = count_lines(words); // Count the total number of lines in the file + line_total = count_lines(words); fseek(words, 0, SEEK_SET); // Reset pointer to beginning of file char temp[2]; // Cannot copy c directly to str. needs a buffer temp[1] = '\0'; // Makes the array a string r = randombytes_uniform(line_total + 1); // Generates random line number to use for string - temp[1] = '\0'; // Makes the array a string - + while ((c = getc(words)) != EOF) { int i; - temp[0] = c; // Temporally move the current character into temp - if ((r == i) && (c != '\n')) { // If the current line is the designated word & it isn't the break character - strcat(str, temp); // Copy the character to the string + temp[0] = c; + if ((r == i) && (c != '\n')) { + strcat(str, temp); } if (c == '\n') { - i++; // Increment the line counter - } + i++; } } - //** Passwords are generated by just printing outputs of different functions. **/ randomize_case(str); generate_integers(); printf("%s", str); @@ -82,6 +77,5 @@ int main (int argc, char **argv) { printf("\n"); fseek(words, 0, SEEK_SET); // Reset pointer to beginning of file // fclose(words); - /** printf("LINE TOTAL: %li\n", line_total); **/ } |