// 随机生成密码
CString MadeRandPwd()
{
int nI = 3; // 密码中数字占三位
int nJ = 3; // 密码中字母占两位
int nK = 2; // 密码中特殊字符占两位
int nLen = nI+nJ+nK;
char aPwd[21] = {0}; // 注意本函数密码最长20位
char aChar[] = {'~', '!', '#', '$' , '%','^', '&', '*', '(', ')'
,'-', '+', '_', '+', '{','}', '[', '}', '\\', '|'
,';', '"', ':', '\'', ',','.', '\/','<', '>', '?'};
int nCharLen = sizeof(aChar)/sizeof(aChar[0]);
srand((unsigned int)time(NULL));
while (1)
{
int i = rand()%nLen;
if (0==aPwd[i])
{
if (nI>0)
{
aPwd[i] = rand()%10 + '0';
nI--;
}
else if (nJ>0)
{
aPwd[i] = rand()%26 + 'A' + ('a'-'A') * (rand()%2);
nJ--;
}
else if (nK>0)
{
aPwd[i] = aChar[rand()%nCharLen];
nK--;
}
if (0 == nI+nJ+nK)
{
break;
}
}
}
CString strPwd(aPwd);
return strPwd;
}