手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp编程>列表

随机产生用户密码

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
  说明:通过随机产生密码,然后将密码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
%>

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!