Password Generator VBScript


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
;'[]}{\|~`:
'   The numbers 0 and 1 have been removed to avoid confusion with the letters O and L.
'   password_length should be a number between 4 and 127, although a limit of 14 is recommended for
'   Win9x clients.  Default is 7
'   Complexity must be 1,2 or 3
'   Uniqueness value of 0 will make each password character unique.  A value of 1 [default] will allow
'       repeated characters.
'   If you don't pass values at the command prompt, you will be prompted for each value.
'
' **************************************************************************

On Error Resume Next
strDebug=1      'set to 0 to turn on Debugging statements
If strDebug=0 Then
wscript.echo "Debugging is ON"
End If

'Define the password seed strings
strSimple="ab*c@def!gh2ij3kl4m#n5op$6qr7st8u%v9w^x&y(z)"
strComplex="abc8defGHIJghijkl3mnoLMNpqr2st^&)uvwxyz9ABCDE4F7KO6PQRS*(TUVWXYZ!@#5$%_+-="
strInsane="abcd_+e-=fghi2jklmQR9Sn5opMNqrs3tuvIJw4x*(;yzABCD),>EFGH7K@#$%^L8OPTUVW./?XYZ!&'[]}{\|~`:"

If wscript.arguments.count >0 then
  if InStr(1,Wscript.arguments(0),"?",vbTextCompare)<>"0" then
    ShowHelp(1)
        wscript.quit
  end if
End If

strTitle="Random Password Generator"

If Wscript.arguments.count < 1 Then
  strLength=InputBox("How long do you want the password to be?",strTitle,"7")
    If strLength="" then
    Wscript.echo "No value entered or job cancelled."
    wscript.quit
    End If
Else
  strLength=wscript.arguments(0)
End If

If Wscript.arguments.count < 2 Then
  strSeed=InputBox("How complex do you want it to be?" & VBCRLF & "1 - simple" & VBCRLF & "2 - complex" & VBCRLF & "3 - insane" & VBCRLF & "4 - Help",strTitle,1)
Select Case strSeed
  Case 1
    strSeed=strSimple
  Case 2
    strSeed=strComplex
  Case 3
    strSeed=strInsane
   Case 4
    ShowHelp(0)
     wscript.quit
  Case Else
   Wscript.echo "Invalid selection.  Please try again."
   Wscript.quit
End Select

Else

strSeed=Wscript.Arguments(1)
Select Case strSeed
  Case 1
    strSeed=strSimple
  Case 2
    strSeed=strComplex
  Case 3
    strSeed=strInsane
   Case 4
    ShowHelp(0)
     wscript.quit
  Case Else
   Wscript.echo "Invalid selection.  Please try again."
   Wscript.quit
End Select

End If

If Wscript.Arguments.Count < 3 Then
  askUnique=InputBox("Do you want all unique characters?  Enter 0 for Yes and 1 for No",strTitle,"1")

Select Case askUnique
 Case 1
 strUnique=1
 Case 0
 strUnique=0
 Case Else
 wscript.echo "Invalid response or operation cancelled"
 wscript.quit
End Select

Else

askUnique=Wscript.Arguments(2)
Select Case askUnique
 Case 1
 strUnique=1
 Case 0
 strUnique=0
 Case Else
 wscript.echo "Invalid response or operation cancelled"
 wscript.quit
End Select

End If

If strDebug=0 then
 wscript.echo "strUnique is set to " & strUnique
End If

Wscript.Echo "Password is " & strPass(strLength,strSeed,strUnique,strDebug)

wscript.quit

'\\\\\\\\\\\\\\\\\\\\\\
Function GenIt(MFactor)
Randomize
GenIt=INT(RND()*MFactor)+1
end Function
'\\\\\\\\\\\\\\\\\\\\\\

'\\\\\\\\\\\\\\\\\\\\\\
Function StrPass(strLength,strSeed,strUnique,strDebug)
'strLength is how long a password to generate
'strSeed is the source string to characters to build the password from
strPass=""

If strDebug=0 then
  wscript.echo "Building a " & strLength & " character password from:" & VBCRLF & strSeed & VBCRLF
End If

MFactor=Len(strSeed)

For x=1 to strLength
 strNum=GenIt(MFactor)
 strNext=Mid(strSeed,strNum,1)
    If strUnique=0 then
        If strDebug=0 then
        wscript.echo "Checking if " & strNext & " has already been used"
        End If
    strPass=strPass & ChkNext(strNext,strPass,strSeed,strDebug)
     Else
    strPass=strPass&strNext
    End If
Next

End Function
'\\\\\\\\\\\\\\\\\\\\\\

'\\\\\\\\\\\\\\\\\\\\\\
Function ChkNext(strNext,strPass,strSeed,strDebug)
strTmp=strNext
MFactor=Len(strSeed)

If InStr(1,strPass,strNext,1) <>0 Then
    If strDebug=0 then
    wscript.echo "Duplicate character"
    End If
 strNum=GenIt(MFactor)
    If strDebug=0 then
    wscript.echo "New number is " & strNum
    End If
 strNext=Mid(strSeed,strNum,1)
    If strDebug=0 then
    wscript.echo "New character to check is " & strNext
    End If
 strTmp=ChkNext(strNext,strPass,strSeed,strDebug)
End if
    If strDebug=0 then
    wscript.echo "At end of function strTmp="&strTmp
    End If
ChkNext=strTmp
    If strDebug=0 then
    wscript.echo "ending ChkNext function"
    End If

End Function
'\\\\\\\\\\\\\\\\\\\\\\

'\\\\\\\\\\\\\\\\\\\\\\
Sub ShowHelp(Detail)

msg=VBCRLF & "RANDPASS.VBS HELP --" & VBCRLF & " This script will generate a random password of X length.  It will build the password from seed strings of increasing complexity." & VBCRLF & "1 - simple:" & VBCRLF & "    " & strSimple & VBCRLF & "2 - complex:" & VBCRLF & "    " & strComplex & VBCRLF & "3 - insane:" & VBCRLF & "    " & strInsane & VBCRLF & VBCRLF & "The numbers 0 and 1 have been removed to avoid confusion with the letters O and L." & VBCRLF

If Detail=0 then
wscript.echo msg
 else
 msg=msg & VBCRLF & " Password_length should be a number between 4 and 127, although a limit of 14 is " & VBCRLF & "recommended for Win9x clients.  Default is 7." & VBCRLF & " Complexity must be 1,2 or 3." & VBCLRF & " A uniqueness value of 0 will make each password character" & VBCRLF & "unique.  A value of 1 [default] will allow repeated characters." & VBCRLF & " If you don't pass values at the command prompt, you will be prompted for each value." & VBCRLF & VBCRLF & "Usage:  cscript //nologo RandPass.vbs [password_length]|[?] [complexity] [uniqueness]" & VBCRLF & "cscript randpass.vbs ? will display this help message." & VBCRLF
 wscript.echo msg
end if

wscript.quit

End Sub



You can leave a response, or trackback from your own site.


Further Reading
    None Found




Leave a Reply

Anti-Spam Quiz:

Twitter Delicious Facebook Digg Stumbleupon Favorites More
338 queries in 3.818 seconds.