<%
function RandomPassword(sText)
on error resume next
Randomize()
iUpperbound = int(left(sText, (len(sText)-2)))
iLowerbound = int(Year(Now) / (second(Now)+ 1))
iRandomNumber = int((iUpperbound - iLowerbound + 1) * Rnd + iLowerbound)
if len(iRandomNumber) < 6 then
do until len(iRandomNumber) = 6
iExtraDigit = int((9-0+1) * Rnd + 0)
iRandomNumber = iRandomNumber &iExtraDigit
loop
end if
sNewPassword = right(sText,1)&iRandomNumber & left(right(sText,2),1)
randompassword = sNewPassword
end function
%>
<HTML>
<BODY>
<%
Response.Write RandomPassword("xq")&"<br>"
Response.Write RandomPassword("!w") & "<br>"
Response.Write RandomPassword("@3") & "<br>"
Response.Write RandomPassword("33") & "<br>"
Response.Write RandomPassword("*^") & "<br>"
%>
</BODY>
</HTML>
<%
Function Password_GenPass( nNoChars, sValidChars )
' nNoChars = 密码的长度
' sValidChars = 有效的字符.如果是空则
( "" )
' 默认为: A-Z 和 a-z 和 0-9
Const szDefault = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789"
Dim nCount
Dim sRet
Dim nNumber
Dim nLength
Randomize 'init random
If sValidChars = "" Then
sValidChars = szDefault
End If
nLength = Len( sValidChars )
For nCount = 1 To nNoChars
nNumber = Int((nLength * Rnd) + 1)
sRet = sRet & Mid( sValidChars, nNumber, 1 )
Next
Password_GenPass = sRet
End Function
%>
例子:
<%
Response.Write "你的密码: " & Password_GenPass( 10, "" )
%>
产生一个10位的密码
<%
Response.Write "你的密码: " & Password_GenPass( 5, "ABCabc" )
%>
产生一个5位的密码,在ABCabc随机产生。
<%
Function Password_GenPass(intEnglish,intNumber,intChar)
Const sEnglish= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" Const sNumber = "0123456789"
Const sChar = "~!@#$%^&*()_{}\|/<>?"
Dim sRet
Dim iEnglist
Dim iNumber
Dim iChar
Dim iLength
Dim intSum
Randomize 'init random
iEnglish = Len( sEnglish )
iNumber = Len(sNumber)
iChar = Len(sChar)
intSum = intEnglish + intNumber + intChar
For i = 1 to intSum
If i < (intEnglish + 1) Then
iLength = Int((iEnglish * Rnd) + 1)
sRet = sRet & Mid(sEnglish,iLength,1)
End If
If (i < intEnglish + intNumber + 1) and (i > intEnglish) Then
iLength = Int((iNumber * Rnd) + 1)
sRet = sRet & Mid(sNumber,iLength,1)
End If
If (i < intSum + 1) and (i > intEnglish + intNumber) Then
iLength = Int((iChar * Rnd) + 1)
sRet = sRet & Mid(sChar,iLength,1)
End If
Next
Password_GenPass = sRe
tEnd Function
%>
<HTML><BODY>
<% Response.Write "你的密码: " & Password_GenPass 3,3,3 & "<br>"%>
</BODY>
</HTML>