重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
C语言实现密码生成器,参考代码如下:
创新互联建站长期为1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为复兴企业提供专业的成都做网站、成都网站建设,复兴网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。
#include
#include
#include
//const char lower_chars[] = "abcdefghijklmnopqrstuvwxyz";
//const char upper_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//const char number_chars[] = "0123456789";
const char lower_chars[] = "abcdefghijkmnpqrstuvwxyz"; // no l or o
const char upper_chars[] = "ABCDEFGHJKLMNPQRSTUVWXYZ"; // no I or O
const char number_chars[] = "23456789"; // no 1 or 0
const char special_chars[] = "!@#$%^*()-=_+[]{};:'\",.?/";
const int _ks_pass_len = 17;
void mkpass(char pass[_ks_pass_len+1])
{
int i = 0, j = 0, k = 0,n = 0;
n = _ks_pass_len/4;
for (; i n; i++)
{
pass[i] = lower_chars[rand()%(strlen(lower_chars))];
pass[i+n] = upper_chars[rand()%(strlen(upper_chars))];
pass[i+2*n] = number_chars[rand()%(strlen(number_chars))];
pass[i+3*n] = special_chars[rand()%(strlen(special_chars))];
}
j = _ks_pass_len - 4*n;
for (i = 0; ij; i#43;#43;) {
pass[i+4*n] = special_chars[rand()%(strlen(special_chars))];
}
//字符乱序
for (i = 0; i 32; i++)
{
j = rand()%(_ks_pass_len);
k = pass[j];
pass[j] = pass[i%_ks_pass_len];
pass[i%_ks_pass_len] = k;
}
pass[_ks_pass_len] = '\0';
}
int _tmain(int argc, _TCHAR* argv[])
{
srand(time(0));
char szPass[_ks_pass_len+1];
for (int i=0; i16; i++)
{
mkpass(szPass);
printf("%s\n",szPass);
}
return 0;
}j; i#43;#43;)
#includestdio.h
#includestdlib.h
#includetime.h
int main()
{
char pool[]=
{
'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z','A','B','C','D',
'E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U','V','W','X',
'Y','Z'
};//随机池
srand(time(0));
char pwd[9];
pwd[8]='\0';//方便作为字符串输出处理
int i=0;
while(i!=8)
{
pwd[i++]=pool[rand()%sizeof(pool)];
}
printf("密码%s",pwd);
}
可以定义两个字符数组;
一个存放正确密码;
另一个数组内的内容由用户输入;
调用strcmp函数,若返回值为0则说明两者完全相等;
列子:
char a[10]="4488" //保存正确密码
char b[10];
gets(b) //用户输入
if(strcmp(a,b)==0)
printf(" 匹配成功 ");
else
printf("匹配失败");
更多追问追答
追问
#include
void main()
{
char a[10]="8844";
char b[10];
gets(b)
if(strcmp(a,b)==0)
printf("yes");
else
printf("no");
getch();