当前位置: 首页 > 图文教程 > 网络编程 > ASP > Asp中随机产生用户密码的代码

ASP
ASP中数据库调用中常见错误的现象和解决方法
ASP取出HTML里面的图片地址的函数
关于分页查询和性能问题
利用Asp生成整站静态
用ASP+XMLHTTP编写一个天气预报程序
轻松检测浏览器是否接受Cookies信息
净化网络环境:ASP程序实现过滤脏话
入门:防范SQL注入攻击的新办法
如何对ASP.NET进行性能优化
ASP无法更新ACCESS数据库解决方法
ASP:利用ASP把图片上传到数据库
ASP:用ASP编程实现网络内容快速查找
ASP:用ASP打造一个小型的网页BBS系统
ASP:用Asp编程实现QQ的在线情况查询
通过表单创建word的一个例子
在ASP中轻松实现记录集分页显示
ASP中实现小偷程序的原理和简单示例
ASP:6行代码实现无组件上传
实用篇:用asp实现QQ在线查询
如何轻松打造ASP计数器

ASP 中的 Asp中随机产生用户密码的代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 46 ::
收藏到网摘: n/a

随机产生用户密码(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)
  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
%>