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

所属分类: 网络编程 / ASP编程 阅读数: 743
收藏 0 赞 0 分享
随机产生用户密码(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  
%> 
更多精彩内容其他人还在看

TsysV1.1 系统文件清单介绍

TsysV1.1 系统文件清单介绍
收藏 0 赞 0 分享

好久没发布新玩意,完成了tsys的少年不在版

好久没发布新玩意,完成了tsys的少年不在版
收藏 0 赞 0 分享

tsys _rss程序

tsys _rss程序
收藏 0 赞 0 分享

TSYS 新闻列表JS调用下载

TSYS 新闻列表JS调用下载
收藏 0 赞 0 分享

使用asp代码突破图片的防盗连

使用asp代码突破图片的防盗连
收藏 0 赞 0 分享

一种理论上最快的Web数据库分页方法

一种理论上最快的Web数据库分页方法
收藏 0 赞 0 分享

asp:debug类调试程序

asp:debug类调试程序
收藏 0 赞 0 分享

如何增加Referer功能--反向链接插件

如何增加Referer功能--反向链接插件
收藏 0 赞 0 分享

pjblog中清空引用的小程序

pjblog中清空引用的小程序
收藏 0 赞 0 分享

光碟工具 Alcohol 120% v1.9.6.4719 下载(附序列号注册码)

光碟工具 Alcohol 120% v1.9.6.4719 下载(附序列号注册码)
收藏 0 赞 0 分享
查看更多