Weak passwords are common source of email and social website accounts hacks. To
ID: 3540595 • Letter: W
Question
Weak passwords are common source of email and social website accounts hacks. To alleviate this problem, the program, when the user chooses a new password, it should determine if it is a legitimately strong password. We are to write a function that validate the password strength. The restrictions that we define as our defined level of strength of passwords is the followings: we make a strength requirement that the password must be at least eight characters long, and must include at least one uppercase and one lowercase letter , one digit. In addition, it must contain at least one string of at least four letters long.
bool isStrongPassword (const char* password)
{
//complete me!
}
Explanation / Answer
bool isStrongPassword(const char* password)
{
bool hasUpper = false;
bool hasLower = false;
bool hasDigit = false;
for(int i =0; i < strlen(password); ++i)
{
if( islower(password[i]) )
hasLower = true;
if( isupper(password[i]) )
hasUpper = true;
if( isdigit(password[i]) )
hasDigit = true;
}
if(hasLower && hasUpper && hasDigit)
{
printf("Strong Password ");
}
else
{
printf("Weak Password ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.