Question: Our password requirements are exactly the same as in the homework problem. Minimum length of twelve characters At least one UPPER CASE letter ( A

Our password requirements are exactly the same as in the homework problem.
Minimum length of twelve characters
At least one UPPER CASE letter (A-Z)
At least one lower case letter (a-z)
At least one digit (0-9)
At least one "special" character (printable, but not alphanumeric)
No space characters
Write a program that reads a list of candidate passwords (the number of passwords in the list is unknown) and states the number of passwords that meet our qualifications. There is no need to use an array in this program; just read the passwords one line at a time (hint, hint), test them, and keep track of the count of valid and invalid passwords.
I have a code, but I don't think it is reading the file line by line and I think its including space characters. How do I get the code to read line by line and make sure there are no space characters?
#include
#include
#include
#include
using namespace std;
bool isValidPassword(const string& password){
if (password.length()<12){
return false;
}
bool hasUpperCase = false;
bool hasLowerCase = false;
bool hasDigit = false;
bool hasSpecialChar = false;
bool hasNoSpace = true
for (char password){
if (isupper(password)){
hasUpperCase = true;
}
else if (islower(password)){
hasLowerCase = true;
}
else if (isdigit(password)){
hasDigit = true;
}
else if (isprint(password) && !isalnum(password)){
hasSpecialChar = true;
}
}
return hasUpperCase && hasLowerCase && hasDigit && hasSpecialChar;
}
int main(){
ifstream inputFile("Passwords.txt");
if (!inputFile.is_open()){
cout << "Error opening file." << endl;
return 1;
}
int validCount =0;
int invalidCount =0;
string password;
while (inputFile >> password){
if (isValidPassword(password)){
validCount++;
}
else {
invalidCount++;
}
}
cout << "Total number of valid passwords are "<< validCount << endl;
cout << "Total number if invalid passwords are "<< invalidCount << endl;
inputFile.close();
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!