随机产生用户密码

因本人从事SP,经常要生成一些随机密码,短信下发给用户,下面就是一段随机生成密码的函数!
把下面的代码保存为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

%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值