我制作了一个密码检查程序,它检查以下标准:-
至少应该有
- 1个大写
- 1个小写
- 1 个特殊字符
- 1 个号码
- 应少于 100 个字符
就是这样。我没有给出任何下限。而且无论我给出什么输入(正确或不正确),程序都会给我与截图中所附相同或相似的输出。
例如:- Pratik10
, pratik10
, pratikten
, pr@tiK10
, 我得到相同的输出"Password is fine and valid"
。
为什么我的程序没有正确检查定义的条件?它甚至没有正确打印密码的计数器。
以下是我的代码:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
int main()
{
char x[100];
int i;
int uc=0;
int lc=0;
int num=0;
int misc=0;
printf("enter your password\n");
scanf("%s",x);
for(i=0;i<100;i++) {
if (isalpha(x[i])) {
if (isupper(x[i])) {
uc++;
}
if (islower(x[i])) {
lc++;
}
}
if (isdigit(x[i])) {
num++;
}
else {
misc++;
}
}
printf("checking your password\n");
printf("%d uc\n",uc);
printf("%d lc\n",lc);
printf("%d num\n",num);
printf("%d misc\n",misc);
if ((uc > 0) && (lc > 0) && (num > 0) && (misc > 0)) {
printf("password is fine and valid\n");
}
else {
if(lc<=0) {
printf("lowercase character(s) missing cannot proceed without inclusion\n");
}
if(uc<=0) {
printf("uppercase character(s) missing cannot proceed without inclusion\n");
}
if(num<=0) {
printf("number(s) missing cannot proceed without inclusion\n");
}
if(misc<=0) {
printf("special character(s) missing cannot proceed without inclusion\n");
}
printf("please include all the missing parameters in combination to validate the password and try again\n\n");
}
return 0;
}
如何纠正这个?
输出: