O蛋 2007-12-19 01:42
随机产生用户密码(good)
说明:通过随机产生密码,然后将密码EMail给注册用户,你可以确认用户的EMail填写是否正确。自动产生的密码往往安全性更高,同时,你可以过滤那些无效的用户。
o
i+?#_^H
<P><BR> 把下面的代码保存为random.asp文件:</P>1L0[7Dj0DO:gWW
<P><%<BR>Sub StrRandomize(strSeed)<BR> Dim i, nSeed <BR> nSeed = CLng(0)<BR> For i = 1 To Len(strSeed)<BR> nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSeed, i, 1))))<BR> Next</P>
D8ms C;Bk7n
<P> Randomize nSeed<BR>End Sub</P>%B
K!Mdz6NbH
<P><BR>Function GeneratePassword(nLength)<BR> Dim i, bMadeConsonant, c, nRnd</P>O
hziO$J
<P> Const strDoubleConsonants = "bdfglmnpst"<BR> Const strConsonants = "bcdfghklmnpqrstv"<BR> Const strVocal = "aeiou"</P>`Q)ZI$E6{*y~ It
<P> GeneratePassword = ""<BR> bMadeConsonant = False</P>.ve _4I2]-dj$S
<P> For i = 0 To nLength<BR> nRnd = Rnd<BR> If GeneratePassword <> "" AND (bMadeConsonant <> True) AND (nRnd < 0.15) Then<BR> c = Mid(strDoubleConsonants, Int(Len(strDoubleConsonants) * Rnd + 1), 1)<BR> c = c & c<BR> i = i + 1<BR> bMadeConsonant = True<BR> Else<BR> If (bMadeConsonant <> True) And (nRnd < 0.95) Then<BR> c = Mid(strConsonants, Int(Len(strConsonants) * Rnd + 1), 1)<BR> bMadeConsonant = True<BR> Else<BR> c = Mid(strVocal,Int(Len(strVocal) * Rnd + 1), 1)<BR> bMadeConsonant = False<BR> End If<BR> End If<BR> GeneratePassword = GeneratePassword & c<BR> Next</P>
j}Hh6Y
<P> If Len(GeneratePassword) > nLength Then<BR> GeneratePassword = Left(GeneratePassword, nLength)<BR> End If<BR>End Function<BR>%></P>
g X$\*W.`w\%M
<P><BR> 然后在你的目标程序中这样调用上面的代码,就可以实现密码的自动生成:(仅仅是一个例子,你可以把他们粘贴到一个Test.asp的文件中,然后运行Test.asp)</P>#^L4e5_TB
<P><!--include file="random.asp" --></P>Y5yGr8da
<P><%<BR>'产生一个六位的密码</P>
C"FV/\L5[ k#zY
<P>StrRandomize CStr(Now) & CStr(Rnd)<BR>response.write GeneratePassword(6)</P>#m6oDF7EQW"PX
<P>%><BR><br><br></P>8uU1}9@.Y~
<P><%</P>
Gn%E&YH^+P [ ?
<P>'产生一个8位的密码<BR>StrRandomize CStr(Now) & CStr(Rnd)<BR>response.write GeneratePassword(8)</P>
@p _MF!r
<P>%><BR><br><br></P>
;C%o+c+[8kjr
<P><BR><%<BR>'产生一个10位的密码<BR>StrRandomize CStr(Now) & CStr(Rnd)<BR>response.write GeneratePassword(10)<BR>%><BR><br><br></P>*L2Q8c"E1s4M'CP
<P><%</P>~n3v0}F7O"rv
<P>'产生1000个密码</P>4\!?FGL
<P>dim t, t2<BR> for t = 1 to 500<BR> For t2 = 1 to 661<BR> StrRandomize CStr(Now) & CStr(Rnd)<BR> next<BR> StrRandomize CStr(Now) & CStr(Rnd)<BR> response.write GeneratePassword(6)<BR> response.write "<br>"<BR>next</P>X8B/N5d#RLz-Z
<P>%></P>