I have been working on a program that will check the eligibility of a password.
In order for password to be eligible it needs to have at least: one uppercase letter; one number; and one dollar sign.
My program does the work checking for the requirements and determining whether the password is good to go or not.
The barrier I'm having right now is that I've tried to make program run until:
- User quits the program by typing "quit";
- Or if user types the correct form of required password.
In order to run such a repetitive process I have decided to use the do-while loop. In order for program to determine that it is time to break out, I have used the following command:
do {...} while (passwordInput != "quit" || passwordClearance != 1);
Unfortunately my program still runs even if the password was correct.
Please give me a clue how do I break out from repetitive process when it is good to go.
// challenge:
// build a program that checks when user enters a password for an uppercase letter, a number, and a dollar sign.
// if it does output that password is good to go.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char passwordInput[50];
int digitCount = 0;
int upperCharacterCount = 0;
int dollarCount = 0;
int passwordClearance = 0;
do {
printf("Enter you password:\n");
scanf(" %s", passwordInput);
for (int i = 0; i < strlen(passwordInput); i++) {
if (isdigit(passwordInput[i])) {
digitCount++;
//continue;
} else
if (isupper(passwordInput[i])) {
upperCharacterCount++;
//continue;
} else
if (passwordInput[i] == '$') {
dollarCount++;
//continue;
}
}
if ((dollarCount == 0) || (upperCharacterCount == 0) || (digitCount == 0)) {
printf("Your entered password does not contain required parameters. Work on it!\n");
} else {
printf("Your entered password is good to go!\n");
passwordClearance = 1;
}
} while (passwordInput != "quit" || passwordClearance != 1);
return 0;
}