首页  新闻动态  文化知识  网络文摘  生活时尚  娱乐休闲  健康频道  外语学习  软件教学  程序设计  独山图片  书店网站 
  程序设计 > Asp/Vbscript > 正文
 

随机生成用户密码

来源:独山在线 [2008-06-05]   浏览次数:565
    说明:通过随机生成密码,然后将密码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
%>
>>上篇:男人女人最需的5种食品
>>下篇:ASP实现数据库仅在需要时打开
 
 
版权所有:独山在线 copyright ©2007-2024 www.dushan.net, All Rights Reserved.
   免责声明:本网转载或链接出于传递更多信息之目的,并不意味着赞同其观点或证实其内容的真实性。
   本站为公益性网站,旨在宣传独山,如有侵犯请和我们联系,经查实将及时删除! 工信部备案:黔ICP备07001263号-3