// logical AND via lookahead: this password matches IF it contains
// at least one lowercase letter
// AND at least one uppercase letter
// AND at least one punctuation character
// AND be at least 6 characters long
Want to place a restriction that there may be no more than 3 lower case characters.
I tried the following with no success (I have been trying for several hours now):
Any suggestions? I am trying to specify what I want using reg expression assertions but maybe I am not an expert on them right now. A small push might clear me up.
#include <regex>
#include <iostream>
#include <iomanip>
#include <string>
int main()
{
std::regex const pw_verify
{
R"__((?=.*[[:punct:]]))__" // at least one punctuation mark
R"__((?=.*[[:upper:]]))__" // at least one uppercase letter
R"__((?=.*[[:lower:]]))__" // at least one lowercase letter
R"__((?!.*?[[:lower:]]{4}))__" // not at least four lowercase letters
R"__(.{6,})__" // at least six characters
};
for (std::string line; std::getline(std::cin, line);)
if (std::regex_match(line, pw_verify))
std::cout << std::quoted(line) << ": valid password\n";
else
std::cout << std::quoted(line) << ": bad password\n";
}