Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Working with athletes who dope

Answered: 1 week ago