如何做一个密码“生成器”?
randompassword.asp
<%
dim i, intnum, intupper, intlower, intrand, strpartpass, genpassword
genpassword = \"\"
randomize
' 用randomize生成随机种子.
for i = 1 to 7
' 循环7次,即创建7位随机密码.
intnum = int(10 * rnd + 48)
' 0-9的ascii码范围是48-57.
intupper = int(26 * rnd + 65)
' a-z的ascii码范围是65-90.
intlower = int(26 * rnd + 97)
' a-z的ascii码范围是97-123.
intrand = int(3 * rnd + 1)
' 对int(3 * rnd + 1)取整得到intrand,会有3种结果,用select case判断当前的intrand值是1,2还是3.如果是1显示数字,是2显示大写字符,是3则显示小写字符.
select case intrand
case 1
strpartpass = chr(intnum)
' 用chr方法换算到对应的ascii值.
case 2
strpartpass = chr(intupper)
case 3
strpartpass = chr(intlower)
end select
genpassword = genpassword & strpartpass
next
randompassword = genpassword
' 将创建的密码保存在变量randompassword中.
%>
<%=\"请保存好,您的密码是:\" & randompassword%>
[1]
上一篇: 数据结构之队列and栈总结分析