C语言中密码校验怎么做
发布网友
发布时间:2022-05-07 18:44
我来回答
共1个回答
热心网友
时间:2022-07-01 02:56
给你个参考:
#include<stdio.h>
#include<conio.h> //用getch()函数时要的文件头
#include<string.h>
#define USER "admin"
#define PWD "admin"
void main()
{
char user[20], pwd[16], ch;
int count=0, i=0;
while(count<3) //3次机会输入正确密码
{
printf("user name:");
gets(user);
printf("password:");
while((ch=getch())!=13&&i<16) //将输入的密码转换成字符****
{
putchar('*');
pwd[i]=ch;
i++;
}
pwd[i]=0;
if(!strcmp(USER,user)&&!strcmp(PWD,pwd))
break;
else
printf("\nincorrect user name or password!\n");
count++;
}
printf("\nlogin successful!\n");
}