Asp中隨機產生用戶密碼的代碼
2024-05-04 11:01:33
供稿:網友
隨機產生用戶密碼(good),說明:通過隨機產生密碼,然后將密碼EMail給注冊用戶,你可以確認用戶的EMail填寫是否正確。
說明:通過隨機產生密碼,然后將密碼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)