VBScript实现密码生成器

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

<!--filename : password generator -2.2.hta-->
<!--Date : 2012/6/20-->
<!--author : moose-->
<html>
<head>
<title>Password Generator</title>
<HTA:APPLICATION
  APPLICATIONNAME="Password Generator"
  ID="PasswordGenerator"
  VERSION="1.0"/>
</head>

<script language="VBScript">
'检查用户输入信息是否合法
Sub checkInfo
	On Error Resume Next 
	'判断长度和个数是否为空
	If pwNumber.value = "" Or pwLength.value="" Then
		errorinfo.innerHTML = "Number and Length must be typed !"
	Else
		'判断是否为数字,如果不是,则会出错
		pn = CInt(pwNumber.value)
		pw = CInt(pwLength.value)
	End If 
	
	aa=0
	bb=0
	cc=0
	dd=0

	If number.Checked Then aa=1
	If lletter.Checked Then bb = 1
	If uletter.Checked Then cc = 1
	If specials.Checked Then dd = 1
	'alert aa&bb&cc&dd

	'长度和个数必须是数字
	If Err.Number <> 0 Then 
		errorinfo.innerHTML = "Must be numeric !"
	Else
		For t=1 To pwNumber.value	
			pwText.innerHTML=generate_password(pwLength.value,aa,bb,cc,dd)
		Next	
	End If	
End Sub


'@param Int length:           密码长度
'@param Boolen number_chars:  是否包含数字
'@param Boolen lower_chars:   是否包含小写字母
'@param Boolen upper_chars:   是否包含大写字母
'@param Boolen special_chars: 是否包含特殊符号
'@return String: 生成的密码
Function generate_password(length, number_chars, lower_chars, upper_chars, special_chars)
    Dim password, chars, i, l
    If number_chars  Then chars = chars & "0123456789"
    If lower_chars   Then chars = chars & "abcdefghijklmnopqrstuvwxyz"
    If upper_chars   Then chars = chars & "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    If special_chars Then chars = chars & "!@#$%^&*()"
    If chars = "" Then errorinfo.innerHTML = "No Input !"
    Randomize : l = Len(chars)
    For i = 1 To length
        password = password & Mid(chars, Int(Rnd * l + 1) ,1)
    Next
    generate_password = password
End Function



</script>

<body bgcolor="white">
<fieldset>
<legend>Password Generator</legend><br/>
&nbsp;&nbsp;Number: <input type="text" name="pwNumber" value="1" /><br/>
&nbsp;&nbsp;Length: <input type="text" name="pwLength" value="8" /><br/>
<br/>
&nbsp;&nbsp;<input type="checkbox" name="number" value="1" />Number
&nbsp;&nbsp;<input type="checkbox" name="lletter" value="2" />Lower Letter
&nbsp;&nbsp;<input type="checkbox" name="uletter" value="4" />Upper Letter
&nbsp;&nbsp;<input type="checkbox" name="specials" value="8" />Specials<br/>
&nbsp;&nbsp;<input type="button" name="ok_btn" value="Generator" onclick="checkInfo" />
<br/><br/>
</fieldset>
<br/>
<span id="pwText" style="font-size:2em"></span>
<span id="errorinfo" style="color:red"></span>
</body>
</html>