randompassword.asp
<%
Dim i, intNum, intUpper, intLower, intRand, strPartPass, genPassword
genPassword = \"\"
Randomize
' 用Randomize生成隨機種子.
For i = 1 to 7
' 循環7次,即創建7位隨機密碼.
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)
' 對Int(3 * Rnd + 1)取整得到intRand,會有3種結果,用select case判斷當前的intRand值是1,2還是3.如果是1顯示數字,是2顯示大寫字符,是3則顯示小寫字符.
Select Case intRand
Case 1
strPartPass = Chr(intNum)
' 用Chr方法換算到對應的ASCII值.
Case 2
strPartPass = Chr(intUpper)
Case 3
strPartPass = Chr(intLower)
End Select
genPassword = genPassword & strPartPass
Next
randomPassword = genPassword
' 將創建的密碼保存在變量randomPassword中.
%>
<%=\"請保存好,您的密碼是:\" & randomPassword%>
[1]