隨機|隨機 說明:通過隨機產生密碼,然後將密碼EMail給註冊使用者,你可以確認使用者的EMail填寫是否正確。自動產生的密碼往往安全性更高,同時,你可以過濾那些無效的使用者。
把下面的代碼儲存為random.asp檔案:
<%
Sub StrRandomize(strSeed)
Dim i, nSeed
nSeed = CLng(0)
For i = 1 To Len(strSeed)
nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSeed, i, 1))))
Next
Randomize nSeed
End Sub
Function GeneratePassword(nLength)
Dim i, bMadeConsonant, c, nRnd
Const strDoubleConsonants = "bdfglmnpst"
Const strConsonants = "bcdfghklmnpqrstv"
Const strVocal = "aeiou"
GeneratePassword = ""
bMadeConsonant = False
For i = 0 To nLength
nRnd = Rnd
If GeneratePassword <> "" AND (bMadeConsonant <> True) AND (nRnd < 0.15) Then
c = Mid(strDoubleConsonants, Int(Len(strDoubleConsonants) * Rnd + 1), 1)
c = c & c
i = i + 1
bMadeConsonant = True
Else
If (bMadeConsonant <> True) And (nRnd < 0.95) Then
c = Mid(strConsonants, Int(Len(strConsonants) * Rnd + 1), 1)
bMadeConsonant = True
Else
c = Mid(strVocal,Int(Len(strVocal) * Rnd + 1), 1)
bMadeConsonant = False
End If
End If
GeneratePassword = GeneratePassword & c
Next
If Len(GeneratePassword) > nLength Then
GeneratePassword = Left(GeneratePassword, nLength)
End If
End Function
%>
然後在你的目標程式中這樣調用上面的代碼,就可以實現密碼的自動產生:(僅僅是一個例子,你可以把他們粘貼到一個Test.asp的檔案中,然後運行Test.asp)
<!--include file="random.asp" -->
<%
'產生一個六位的密碼
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(6)
%>
<br><br>
<%
'產生一個8位的密碼
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(8)
%>
<br><br>
<%
'產生一個10位的密碼
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(10)
%>
<br><br>
<%
'產生1000個密碼
dim t, t2
for t = 1 to 500
For t2 = 1 to 661
StrRandomize CStr(Now) & CStr(Rnd)
next
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(6)
response.write "<br>"
next
%>