随机产生长度不少于6位密码

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_33870933/article/details/82886317
//随机产生长度不少于6位 包含大写、小写、数字、特殊字符至少三种的密码
string randpass(int n)
{
	string res="";
	if(n<6)
	{	
		cout<<"长度不能少于6位"<<endl;
		return res;
	}
	int count=0;
	int lownum=0,highnum=0,spnum=0,num=0;//分别存小写、大写、特殊字符、数字个数
	srand(time(NULL));
	while(!(lownum&&highnum&&(spnum||num)||(lownum||highnum)&&num&&spnum))
	{
		num=rand()%(n-2);
		lownum=rand()%(n-num-1);
	    highnum=rand()%(n-lownum-num);
		spnum=n-num-highnum-lownum;
	}
	int select = -1;
	int i=0;
	while(i<n)
	{
		select = rand()%4;
		switch(select)
		{
		case 0:
			if(num<=0)break;
			res+=rand()%10+'0';
			num--;
			i++;
				break;
		case 1:
			if(lownum<=0)break;
			res+=rand()%26+'a';
			lownum--;
			i++;
				break;
		case 2:
			if(highnum<=0)break;
			res+=rand()%26+'A';
			highnum--;
			i++;
				break;
		case 3:
			if(spnum<=0)break;
			res+=rand()%('/'-'('+1)+'(';
			spnum--;
			i++;
				break;
		}
	}
	
	cout<<res<<endl;

	return res;
}

生成不少于6位的随机密码,生成的随机密码必须至少包含大写字母、小写字母、数字、特殊字符四种中任意三种。

参考了:https://blog.csdn.net/liwei1205/article/details/78071861

展开阅读全文

asp随机产生密码

12-13

random.asprn<%rnSub StrRandomize(strSeed)rn  Dim i, nSeed rn  nSeed = CLng(0)rn  For i = 1 To Len(strSeed)rn    nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSeed, i, 1))))rn  Nextrnrn  Randomize nSeedrnEnd SubrnrnrnFunction GeneratePassword(nLength)rn  Dim i, bMadeConsonant, c, nRndrnrn  Const strDoubleConsonants = "bdfglmnpst"rn  Const strConsonants = "bcdfghklmnpqrstv"rn  Const strVocal = "aeiou"rnrn  GeneratePassword = ""rn  bMadeConsonant = Falsernrn  For i = 0 To nLengthrn    nRnd = Rndrn    If GeneratePassword <> "" AND (bMadeConsonant <> True) AND (nRnd < 0.15) Thenrn      c = Mid(strDoubleConsonants, Int(Len(strDoubleConsonants) * Rnd + 1), 1)rn      c = c & crn  i = i + 1rn      bMadeConsonant = Truern    Elsern      If (bMadeConsonant <> True) And (nRnd < 0.95) Thenrn        c = Mid(strConsonants, Int(Len(strConsonants) * Rnd + 1), 1)rn        bMadeConsonant = Truern      Elsern        c = Mid(strVocal,Int(Len(strVocal) * Rnd + 1), 1)rn        bMadeConsonant = Falsern      End Ifrn    End Ifrn    GeneratePassword = GeneratePassword & crn  Nextrnrn  If Len(GeneratePassword) > nLength Thenrn    GeneratePassword = Left(GeneratePassword, nLength)rn  End IfrnEnd Functionrn%>rnrnTest.asprnrnrn<%rn'产生一个六位的密码rnrnStrRandomize CStr(Now) & CStr(Rnd)rnresponse.write GeneratePassword(6)rnrn%>rn rnrn<%rnrn'产生一个8位的密码rnStrRandomize CStr(Now) & CStr(Rnd)rnresponse.write GeneratePassword(8)rnrn%>rn rnrnrn<%rn'产生一个10位的密码rnStrRandomize CStr(Now) & CStr(Rnd)rnresponse.write GeneratePassword(10)rn%>rn rnrn<%rnrn'产生1000个密码rnrndim t, t2rn  for t = 1 to 500rn  For t2 = 1 to 661rn  StrRandomize CStr(Now) & CStr(Rnd)rn  nextrn  StrRandomize CStr(Now) & CStr(Rnd)rn  response.write GeneratePassword(6)rn  response.write " "rnnextrn%>rn我用上面的代码产生随机密码,但是有错误,执行test.asp.总说"StrRandomize" 类型不匹配,请问是为什么? 论坛

没有更多推荐了,返回首页