<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function getRandomNum(lbound, ubound)
{
return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
function getRandomChar(number, lower, upper, other, extra)
{
var numberChars = "0123456789";
var lowerChars = "abcdefghijklmnopqrstuvwxyz";
var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'",<.>/? ";
var charSet = extra;
if (number == true)
charSet += numberChars;
if (lower == true)
charSet += lowerChars;
if (upper == true)
charSet += upperChars;
if (other == true)
charSet += otherChars;
return charSet.charAt(getRandomNum(0, charSet.length));
}
function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther,
latterNumber, latterLower, latterUpper, latterOther)
{
var rc = "";
if (length > 0)
rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
for (var idx = 1; idx < length; ++idx)
{
rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
}
return rc;
}
// End -->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<center>
<table width=80% border=0>
<tr align=center>
<td>
<form name="myform">
<table border=0>
<tr>
<td>
密码前几位包括:
</td>
<td>
<input type=checkbox name=firstNumber checked>数字
<input type=checkbox name=firstLower checked>小写字母
<input type=checkbox name=firstUpper checked>大写字母
<input type=checkbox name=firstOther>其它
</td>
</tr>
<tr>
<td>
密码后几位包括:
</td>
<td>
<input type=checkbox name=latterNumber checked>数字
<input type=checkbox name=latterLower checked>小写字母
<input type=checkbox name=latterUpper checked>大写字母
<input type=checkbox name=latterOther>其它
</td>
</tr>
<tr>
<td>
密码长度:
</td>
<td>
<input type=text name=passwordLength value="8" size=3>
</td>
</tr>
<tr>
<td>
自定密码特征:
</td>
<td>
<input type=text name=extraChars size=20>
</td>
</tr>
</table>
</td>
</tr>
<tr align=center>
<td>
密码:
<input type=text name=password size=20>
<br>
<input type=button value="产生密码" onClick="document.myform.password.value =
getPassword(document.myform.passwordLength.value, document.myform.extraChars.value,
document.myform.firstNumber.checked, document.myform.firstLower.checked,
document.myform.firstUpper.checked, document.myform.firstOther.checked,
document.myform.latterNumber.checked, document.myform.latterLower.checked,
document.myform.latterUpper.checked, document.myform.latterOther.checked);"/>
</form>
</td>
</tr>
</table>
</center>
<SCRIPT>
function scram(v)
{
if(v>20)
{
alert("Too many symbols, change "+v+" to a lesser value, 20 or under.");document.cow.noyey.focus()
}
else
{
i=0
str=""
while(i<v)
{
x=Math.round(Math.random()*100)
if(x<33 || x>255)
{}
else
{
i++
str+=String.fromCharCode(x)
}
}
document.cow.noy.value=str
}
}
</SCRIPT>
<FORM name="cow">
<div align="center">随机的字符:
<INPUT TYPE="Text" name="noy" value="" size="20" onFocus="this.blur()"/>
<br>
请输入字符(max 20):
<INPUT TYPE="Text" name="noyey" value="20" size="4"/>
<br>
<input type="button" onClick="scram(noyey.value)" value="产生文字"/>
<INPUT TYPE="reset"/>
</div>
</FORM>
</body>
</html>
javascript随机密码产生器
最新推荐文章于 2023-10-18 17:52:42 发布