diff --git a/Makefile b/Makefile index 4bed667..ba5d4f9 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ TARGETS = passgen BINARYOUT_TARGETS = passgen.o CPPFLAGS += -I./include -CXXFLAGS += -std=c++20 -O2 +CXXFLAGS += -O2 ifeq ($(OS),Windows_NT) diff --git a/README.md b/README.md index 41ec339..9010f3c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,22 @@ # passgen +passgen generate passphrases based on wordlists. Usage: ``` -passgen +Usage: passgen [options] + +Options: + -h, --help Display this help message and exit + -s, --short Use the short EFF wordlist + -l, --large Use the large EFF wordlist (dfault) + --camelcase, -cc Generate passwords in CamelCase format + -p , --path + Use a custom wordlist file located at + -wc , --wordcount + Amount of words to use for passphrase + --separator Specify a character to use as a separator between words, default = `-` + +Description: + Generate passphrases based on wordlists. ``` example output: diff --git a/compile_commands.json b/compile_commands.json deleted file mode 100644 index cdc369a..0000000 --- a/compile_commands.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "arguments": [ - "/usr/bin/g++", - "-std=c++20", - "-O2", - "-I./include", - "-c", - "-o", - "passgen.o", - "passgen.cpp" - ], - "directory": "/home/mans/dev/passgen", - "file": "/home/mans/dev/passgen/passgen.cpp", - "output": "/home/mans/dev/passgen/passgen.o" - } -] diff --git a/passgen.cpp b/passgen.cpp index ee27eb3..c03f9b0 100644 --- a/passgen.cpp +++ b/passgen.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -19,12 +18,11 @@ enum WordlistType { WORDLIST_EFF_LARGE, WORDLIST_EFF_SHORT, WORDLIST_CUSTOM }; struct PassgenOptions { bool help = false; - WordlistType wordlist_type = WORDLIST_EFF_LARGE; + WordlistType wordlist_type = WORDLIST_EFF_SHORT; int wordcount = 5; bool camelcase = false; std::string seperator = "-"; std::optional wordlist_path; - std::optional outfile; }; typedef std::function NoArgHandle; @@ -77,11 +75,11 @@ PassgenOptions parse_options(int argc, const char* argv[]) { k->second(settings, {argv[i]}); } else { throw std::runtime_error {"missing param after " + opt}; - exit(1); + std::exit(1); } } else { std::cerr << "unrecognized command-line option " << opt << std::endl; - exit(1); + std::exit(1); } } return settings; @@ -91,25 +89,20 @@ std::vector getWordlist(PassgenOptions opts) { std::vector map; - if (opts.wordlist_type == WORDLIST_EFF_LARGE) + if (opts.wordlist_type != WORDLIST_CUSTOM) { std::stringstream ss; - ss.write(reinterpret_cast(eff_large_wordlist_txt), eff_large_wordlist_txt_len); + if (WORDLIST_EFF_SHORT) { + ss.write(reinterpret_cast(eff_short_wordlist_1_txt), eff_short_wordlist_1_txt_len); + } else { + ss.write(reinterpret_cast(eff_large_wordlist_txt), eff_large_wordlist_txt_len); + } std::string line; while (std::getline(ss, line)) { map.push_back(line); } } - else if (opts.wordlist_type == WORDLIST_EFF_SHORT) - { - std::stringstream ss; - ss.write(reinterpret_cast(eff_short_wordlist_1_txt), eff_short_wordlist_1_txt_len); - std::string line; - while (std::getline(ss, line)) { - map.push_back(line); - } - } - else if (opts.wordlist_type == WORDLIST_CUSTOM && opts.wordlist_path.has_value()) + else if (opts.wordlist_path.has_value()) { std::string path = opts.wordlist_path.value(); std::ifstream file(path); @@ -119,8 +112,10 @@ std::vector getWordlist(PassgenOptions opts) map.push_back(line); } } else { - std::cout << std::format("ERROR: failed to open '{}'\n", path); + std::cout << "ERROR: failed to open '" << path << "'" << std::endl; } + } else { + std::cout << "ERROR: no wordlist specified" << std::endl; } return map; @@ -135,13 +130,13 @@ Usage: passgen [options] Options: -h, --help Display this help message and exit - -s, --short Use the short EFF wordlist - -l, --large Use the large EFF wordlist (dfault) + -s, --short Use the short EFF wordlist (dfault) + -l, --large Use the large EFF wordlist --camelcase, -cc Generate passphrase in CamelCase format -p , --path Use a custom wordlist file located at -wc , --wordcount - Amount of words to use for passphrase + Amount of words to use for passphrase, default = 5 --separator Specify a character to use as a separator between words, default = `-` Description: