#include <bits/stdc++.h>
using namespace std;
#define N 6
void identifying_Code (char str[],int n)
{
int i,j,len;
char pstr[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJLMNOPQRSTUVWXYZ";
len = strlen(pstr);
srand(time(NULL));
for (i = 0; i < n; i++)
{
j = rand()%len; //生成0~len-1的随机数
str[i] = pstr[j];
}
str[i] = '\0';
}
int main()
{
int n = 3;
int flag = 0;
char code[7],str[7];
while (n)
{
identifying_Code (code,N);
cout<<"请输入验证码:"<<code<<" (你还有"<<n<<"次机会)"<<endl;
scanf("%s",str);
n--;
if(strcasecmp(code,str) == 0) //不区分大小写
{
n = 0;
flag = 1;
cout<<"验证正确."<<endl;
}
}
if (flag == 0)
cout<<"验证失败."<<endl;
return 0;
}
using namespace std;
#define N 6
void identifying_Code (char str[],int n)
{
int i,j,len;
char pstr[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJLMNOPQRSTUVWXYZ";
len = strlen(pstr);
srand(time(NULL));
for (i = 0; i < n; i++)
{
j = rand()%len; //生成0~len-1的随机数
str[i] = pstr[j];
}
str[i] = '\0';
}
int main()
{
int n = 3;
int flag = 0;
char code[7],str[7];
while (n)
{
identifying_Code (code,N);
cout<<"请输入验证码:"<<code<<" (你还有"<<n<<"次机会)"<<endl;
scanf("%s",str);
n--;
if(strcasecmp(code,str) == 0) //不区分大小写
{
n = 0;
flag = 1;
cout<<"验证正确."<<endl;
}
}
if (flag == 0)
cout<<"验证失败."<<endl;
return 0;
}