ASP版的
JavaScript版的
<
%
function makePassword(maxLen) ' 方法一
Dim strNewPass
Dim whatsNext, upper, lower, intCounter
Randomize
For intCounter = 1 To maxLen
whatsNext = Int (( 3 ) * Rnd + 0 )
If whatsNext = 0 Then ' 生成大写字母
' 'character
upper = 90
lower = 65
Elseif whatsNext = 1 then ' 生在数字
upper = 57
lower = 48
else ' 生成小写字母
upper = 122
lower = 97
End If
strNewPass = strNewPass & Chr ( Int ((upper - lower + 1 ) * Rnd + lower))
Next
makePassword = strNewPass
end function
Function RoundStr( str,Num) ' 方法二
s = ""
for i = 1 to Num
Randomize
strLen = Len (str)
t = Round (( RND * (strLen - 1 )) + 1 )
s = s & mid (str,t, 1 )
Next
RoundStr = s
End Function
' response.write makePassword(10)&"<br>"
tmp = " 0123456789abcdefghijklmnopqrstopwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
' response.write RoundStr(tmp,10)&"<BR>"
% >
function makePassword(maxLen) ' 方法一
Dim strNewPass
Dim whatsNext, upper, lower, intCounter
Randomize
For intCounter = 1 To maxLen
whatsNext = Int (( 3 ) * Rnd + 0 )
If whatsNext = 0 Then ' 生成大写字母
' 'character
upper = 90
lower = 65
Elseif whatsNext = 1 then ' 生在数字
upper = 57
lower = 48
else ' 生成小写字母
upper = 122
lower = 97
End If
strNewPass = strNewPass & Chr ( Int ((upper - lower + 1 ) * Rnd + lower))
Next
makePassword = strNewPass
end function
Function RoundStr( str,Num) ' 方法二
s = ""
for i = 1 to Num
Randomize
strLen = Len (str)
t = Round (( RND * (strLen - 1 )) + 1 )
s = s & mid (str,t, 1 )
Next
RoundStr = s
End Function
' response.write makePassword(10)&"<br>"
tmp = " 0123456789abcdefghijklmnopqrstopwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
' response.write RoundStr(tmp,10)&"<BR>"
% >
<
script
>
function makePassword(maxLen)
{
var strNewPass = "" ;
var whatsNext, upper, lower, intCounter;
for (intCounter = 1 ;intCounter <= maxLen;intCounter ++ )
{
whatsNext = Math.floor( 3 * Math.random());
switch (whatsNext)
{
case 0 : // 生成大写字母
upper = 90 ;
lower = 65 ;
break ;
case 1 : // 生成数字
upper = 57 ;
lower = 48 ;
break ;
case 2 : // 生成小写字母
upper = 122 ;
lower = 97 ;
break ;
}
strNewPass = strNewPass + (String.fromCharCode(Math.floor((upper - lower + 1 ) * Math.random() + lower)));
}
return strNewPass
}
document.write(makePassword( 13 ))
</ script >
function makePassword(maxLen)
{
var strNewPass = "" ;
var whatsNext, upper, lower, intCounter;
for (intCounter = 1 ;intCounter <= maxLen;intCounter ++ )
{
whatsNext = Math.floor( 3 * Math.random());
switch (whatsNext)
{
case 0 : // 生成大写字母
upper = 90 ;
lower = 65 ;
break ;
case 1 : // 生成数字
upper = 57 ;
lower = 48 ;
break ;
case 2 : // 生成小写字母
upper = 122 ;
lower = 97 ;
break ;
}
strNewPass = strNewPass + (String.fromCharCode(Math.floor((upper - lower + 1 ) * Math.random() + lower)));
}
return strNewPass
}
document.write(makePassword( 13 ))
</ script >
<
INPUT
TYPE
="text"
NAME
="Password"
>
< INPUT TYPE ="button" value ="随机生成密码" onClick ="document.getElementById('Password').value=(makePassword(13))" >
< INPUT TYPE ="button" value ="随机生成密码" onClick ="document.getElementById('Password').value=(makePassword(13))" >