程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C >> 關於C >> 密碼生成器C實現

密碼生成器C實現

編輯:關於C
#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; i {
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; i<16; i++)
{
mkpass(szPass);
printf("%s\n",szPass);
}
return 0;
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved