注册帐号时密码随机生成的ASP代码

2008-02-23 09:28:05来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

ASP生成随机密码的两个函数:
函数一
<%
function makePassword(byVal maxLen)
Dim strNewPass
Dim whatsNext, upper, lower, intCounter
Randomize
For intCounter = 1 To maxLen
whatsNext = Int((1 - 0 1) * Rnd 0)
If whatsNext = 0 Then
'character
upper = 90
lower = 65
Else
upper = 57
lower = 48
End If
strNewPass = strNewPass & Chr(Int((upper - lower 1) * Rnd lower))
Next
makePassword = strNewPass
end function
%>
makePassword(str) 'str 密码的位数

函数二
<% Function gen_key(digits)
dim char_array(35)
char_array(0) = "0"
char_array(1) = "1"
char_array(2) = "2"
char_array(3) = "3"
char_array(4) = "4"
char_array(5) = "5"
char_array(6) = "6"
char_array(7) = "7"
char_array(8) = "8"
char_array(9) = "9"
char_array(10) = "A"
char_array(11) = "B"
char_array(12) = "C"
char_array(13) = "D"
char_array(14) = "E"
char_array(15) = "F"
char_array(16) = "G"
char_array(17) = "H"
char_array(18) = "I"
char_array(19) = "J"
char_array(20) = "K"
char_array(21) = "L"
char_array(22) = "M"
char_array(23) = "N"
char_array(24) = "O"
char_array(25) = "P"
char_array(26) = "Q"
char_array(27) = "R"
char_array(28) = "S"
char_array(29) = "T"
char_array(30) = "U"
char_array(31) = "V"
char_array(32) = "W"
char_array(33) = "X"
char_array(34) = "Y"
char_array(35) = "Z"
randomize
do while len(output) < digits
num = char_array(Int(35 * Rnd 0))
output = output num
loop
gen_key = output
End Function
%>
gen_key(str) 'str为密码位数
这个函数还可以扩展。。如果你还要加上“大小写敏感区分大小写”特性的话,修改数组大小为char_array(50),然后在后面列出所有可能的小写字符。例如:
char_array(36) = "a"
char_array(37) = "b"
...............类推

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:利用ASP打造网站论坛DIY -6

下一篇:页面自动刷新,又不用让用户按回车键来提交数据