In response to a question on Information Security on brute-forcing passwords, I wrote code that helped solve the problem:
Generate a password list of 10 character passwords containing only a combination of 3 - 6 numbers and 3 - 6 uppercase letters.
I'd like a code review done of the snippet I wrote. I don't know really anything about optimizing software. I can write it (self-taught) but I don't have the deep insights needed to improve already working software, so I've started posting code snippets in here for you guys to give me insights. I really think this channel is great and without further ado, I'll get to it.
#include <iostream>
#include <vector>
#include <random>
#include <string>
const char charset[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','8','9'};
int main()
{
std::cout << "Please enter the number of passwords to generate here: ";
int num_pass;
std::cin >> num_pass;
std::random_device dev;
std::mt19937_64 rng(dev());
std::vector<std::string> passwds;
std::uniform_int_distribution<std::mt19937_64::result_type> dist(0, sizeof(charset) - 1);
for (int i = 0; i < num_pass; ++i) {
std::string pass = "";
int num_nums = 0, num_chars = 0;
while (pass.length() < 10) {
char c = charset[dist(rng)];
if (isdigit(c) && num_nums < 6) {
pass += c;
num_nums++;
}
else if (isalpha(c) && num_chars < 6) {
pass += c;
num_chars++;
}
}
passwds.push_back(pass);
std::cout << pass << std::endl;
}
std::cin.get();
}
```