功能介绍:该程序可以生成密码字符库pwdcont中字符随机组合,长度范围在6-63的密码、密钥
说明:密码字符库和密码的长度范围可自行更改
源码:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
char pwdcont[]="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
char* GeneratePassword(int pwd_size)
{
int i;
int random;
char *Password = (char *)malloc(pwd_size + 1);
srand((unsigned)time(NULL));
for(i = 0;i < pwd_size;i++)
{
random = rand()%(strlen(pwdcont));
*(Password + i) = pwdcont[random];
}
*(Password + i)= '\0';
return Password;
}
int main()
{
int random;
char *Password;
srand((unsigned)time(NULL));
for(int i=0;i<10;i++)
{
Sleep(100);
random=rand()%(58)+6;//密码的长度范围 (6-63)
printf("random = %d\n",random);
Password = GeneratePassword(random);
printf("Password = %s\n",Password);
}
free(Password);
return 0;
}
运行结果: