Skip to content

Instantly share code, notes, and snippets.

@JellyWX
Last active February 2, 2018 10:38
Show Gist options
  • Save JellyWX/a6bd80a4b7946df8485a24b2a57541c9 to your computer and use it in GitHub Desktop.
Save JellyWX/a6bd80a4b7946df8485a24b2a57541c9 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <map>
int main()
{
std::string term = "";
std::map<std::string, bool> missing;
bool complete = false;
do {
complete = true;
missing["upper"] = false;
missing["lower"] = false;
missing["number"] = false;
missing["special"] = false;
std::cout << "Enter a word: ";
std::getline(std::cin, term);
if (term.size() < 8){
std::cout << "Your password must be longer than 8 characters" << std::endl;
complete = false;
continue;
}
for(char c : term){
if (65 <= int(c) and int(c) <= 90){
missing["upper"] = true;
}
else if (97 <= int(c) and int(c) <= 122) {
missing["lower"] = true;
}
else if (48 <= int(c) and int(c) <= 57) {
missing["number"] = true;
} else {
missing["special"] = true;
}
}
for (auto& kv : missing) {
if (not kv.second) {
std::cout << "Your password must contain a " << kv.first << " character!" << std::endl;
complete = false;
}
}
} while(not complete);
std::cout << "Welcome!" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment