#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
static int validPassword(const char* password) {
int hasUpper = 0, hasDigit = 0, hasDollar = 0 /*, hasLower = 0*/;
const unsigned char* p = (const unsigned char*)password;
whilefor(*p; *p; ++p) {
if(isupper(*p))
hasUpper = 1;
/*else if(islower(*p))
hasLower = 1;*/
else if(isdigit(*p))
hasDigit = 1;
else if(*p == '$')
hasDollar = 1;
}
return hasUpper && hasDigit && hasDollar /* && hasLower*/;
}
int main() {
char password[32];
puts("Please enter a password having an upper case letter, a number"
" and also a $ sign: ");
if(scanf("%31s", password) != 1) {
puts("Could not get the password.");
return EXIT_FAILURE;
}
if(strlen(password) > 30) {
puts("Password is too long.");
return EXIT_FAILURE;
}
if(!validPassword(password)) {
puts("Password must contain an upper case letter, a number and a $ sign.");
return EXIT_FAILURE;
}
puts("Nice Password!");
return 0;
}