randompassword.asp
%
Dim i, intNum, intUpper, intLower, intRand, strPartPass, genPassword
genPassword = \"\"
Randomize
' 用Randomize生成隨機(jī)種子.
For i = 1 to 7
' 循環(huán)7次,即創(chuàng)建7位隨機(jī)密碼.
intNum = Int(10 * Rnd + 48)
' 0-9的ASCII碼范圍是48-57.
intUpper = Int(26 * Rnd + 65)
' A-Z的ASCII碼范圍是65-90.
intLower = Int(26 * Rnd + 97)
' a-z的ASCII碼范圍是97-123.
intRand = Int(3 * Rnd + 1)
' 對(duì)Int(3 * Rnd + 1)取整得到intRand,會(huì)有3種結(jié)果,用select case判斷當(dāng)前的intRand值是1,2還是3.如果是1顯示數(shù)字,是2顯示大寫字符,是3則顯示小寫字符.
Select Case intRand
Case 1
strPartPass = Chr(intNum)
' 用Chr方法換算到對(duì)應(yīng)的ASCII值.
Case 2
strPartPass = Chr(intUpper)
Case 3
strPartPass = Chr(intLower)
End Select
genPassword = genPassword strPartPass
Next
randomPassword = genPassword
' 將創(chuàng)建的密碼保存在變量randomPassword中.
%>
%=\"請(qǐng)保存好,您的密碼是:\" randomPassword%>
[1]