#include
#include
#include
#include
#include
#include
char* CreateVarificationCode(char dest[], int len)//生成验证码
{
int i, isNum, isUpp;
for(i = 0; i < len;="">
{
isNum = rand() % 2;
if(isNum)
{
dest[i] = rand() % 10 + '0';//生成一个随机的数字字符
}
else
{
isUpp = rand() % 2;//Uppercase
if(isUpp)
{
dest[i] = rand() % 26 + 'A';//生成随机的大写字母
}
else
{
dest[i] = rand() % 26 + 'a';//生成随机的小写字母
}
}
}
dest[i] = '\0';//末尾要添加字符串结束标志'\0'
return dest;
}
void InputPassword(char *pw)//获取用户输入的密码
{
char ch;
while((ch = getch()) != 13)//如果不是回车就一直循环
{
*pw++ = ch;//将密码字符保存到数组中
printf('*');//在屏幕上打印一个星
}
*pw = '\0';//末尾要添加字符串结束标志'\0'
}
int main()
{
char *password = '1234';//系统密码
char myPassword[10]; //用户输入的密码
char varify[10]; //存放系统生成的验证码
char myVarify[10]; //用户输入的验证码
char answer = 'y';
int i;
srand((unsigned)time(0));
while('y' == answer)
{
system('cls');//清空屏幕
printf('\n-------------银行登录验证-------------\n');
printf('请输入密码: ');
InputPassword(myPassword);
printf('\n请输入验证码【%s】: ', CreateVarificationCode(varify, 8));
scanf('%10s', myVarify);//获取用户输入的验证码
printf('///开始验证');
for(i = 0; i < 6;="">
{
Sleep(500);
printf('.');
}
if(strcmp(myPassword, password))
{
printf('\n对不起,你输入的密码错误!\n');
printf('是否重新输入?(y or n): ');
while(1 != scanf(' %c', &answer) || (answer != 'y' && answer != 'n'))
{
printf('选择错误!请重新输入(y or n): ');
fflush(stdin);
}
}
else if(strcmp(myVarify, varify))
{
printf('\n对不起,你输入的验证码不正确!\n');
printf('是否重新输入?(y or n): ');
while(1 != scanf(' %c', &answer) || (answer != 'y' && answer != 'n'))
{
printf('选择错误!请重新输入(y or n): ');
fflush(stdin);
}
}
else
{
system('cls');
printf('\n验证正确!欢迎进入网上银行系统....\n');
answer = 'n';
}
}
getch();
return 0;
}
联系客服