随机产生用户密码
yoken
阅读:1265
2007-10-06 23:40:00
评论:0
把下面的代码保存为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
%>
转载保留链接!网址:https://80920140.com/post/130.html
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源; 2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任; 3.作者投稿可能会经我们编辑修改或补充。
发表评论