I am currently working on the following task:
A good password must have at least a minimum length of 8 characters and needs to contain at least three digits. write a c program to check whetehr a password is good or not a password returning true or false.
THis is my code.
However, I am still comfused how to make it check existence of 3 digits at least!
PS: I am new to programing in general.
'''#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
int main()
{
char password[100];
bool hasupper = false;
bool haslower= false;
bool hasdigit= false;
scanf("%s", password);
if ( strlen(password)<8){
printf("Too short");
}
for(int i=1; i<strlen(password); i++){
if (isupper(password[i])){
hasupper=true;
}
if (islower(password[i])){
haslower=true;
}
if (isdigit(password[i])){
hasdigit=true;
}
if(hasdigit && hasdigit && hasdigit && haslower && hasupper){
printf("true");
}
else {
printf("false!");
}
}
return 0;
}'''
Aucun commentaire:
Enregistrer un commentaire