A password for a computer system must 1) have exactly 8 characters 2) consist of
ID: 3623381 • Letter: A
Question
A password for a computer system must1) have exactly 8 characters
2) consist of only alphabetic characters and digits
3) have at least one digit
4) have at least one alphabetic character
write as program accept or reject a sequence of characters entered from the keyboard as a password. If the input does not meet the requirments for a password have the program ask for another attempt and specify which requirment was not meet. If the password meets the requirment should state the fact and terminate.
Explanation / Answer
please rate - thanks
#include <stdio.h>
#include<conio.h>
int main()
{char pw[15];
int good,digit,alpha,i;
do
{digit=0;
alpha=0;
good=0;
printf("Enter a password: ");
scanf("%s",&pw);
for(i=0;i<pw[i]!='';i++)
if(isdigit(pw[i]) )
digit++;
else if(isalpha(pw[i]))
alpha++;
if(i!=8)
{printf("must have exactly 8 characters ");
good=1;
}
if(digit==0)
{printf("must have at least 1 digit ");
good=1;
}
if(alpha==0)
{printf("must have at least 1 alphabetic character ");
good=1;
}
if(digit+alpha!=8)
{printf("must have only alphabetic characters and digits ");
good=1;
}
printf(" ");
}while(good!=0);
printf("%s is a valid password ",pw);
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.