44 {
45 const std::string upper = "ABCDEFGHJKLMNPQRSTUVWXYZ";
46 const std::string
lower =
"abcdefghijkmnopqrstuvwxyz";
47 const std::string digits = "23456789";
48 const std::string symbols = "!@#$%^&*()-_=+[]{}.?";
49
50 std::vector<std::string> enabledSets;
51 std::string allChars;
52
53 if (useUpper) {
54 enabledSets.push_back(upper);
55 allChars += upper;
56 }
57 if (useLower) {
58 enabledSets.push_back(lower);
60 }
61 if (useDigits) {
62 enabledSets.push_back(digits);
63 allChars += digits;
64 }
65 if (useSymbols) {
66 enabledSets.push_back(symbols);
67 allChars += symbols;
68 }
69
70 if (enabledSets.empty()) {
71 throw std::runtime_error("Nessun set di caratteri abilitato");
72 }
73
74 if (length < enabledSets.size()) {
75 length = enabledSets.size();
76 }
77
78 std::string password;
79 password.reserve(length);
80
81 for (const auto& set : enabledSets) {
83 }
84
85 while (password.size() < length) {
87 }
88
89 static thread_local std::random_device rd;
90 static thread_local std::mt19937 gen(rd());
91 std::shuffle(password.begin(), password.end(), gen);
92
93 return password;
94}
static char randomFrom(const std::string &charset)
std::string lower(std::string value)