如何做一个密码“生成器”?

网络编程 2021-07-05 11:26www.168986.cn编程入门

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-9ASCII码范围是48-57.

intUpper = Int(26 Rnd + 65)

' A-ZASCII码范围是65-90.

intLower = Int(26 Rnd + 97)

' a-zASCII码范围是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]

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by