Article ID: 199323
Article Last Modified on 11/1/2006
For /f "tokens=1,2 delims=," %b in (FileName) do net user %b %c
,user1,password1
,user2,password2
DECLARE FUNCTION IsDuplicated% (mPwd AS STRING)
DECLARE FUNCTION CreatePassword$ (mNumChar AS INTEGER)
'-- Declare variables you are using
Dim gNumCreated As Integer '-- Keeps track of number of passwords created
Dim NumPass As Integer '-- Number of passwords you want
Dim NumChar As Integer
Dim Tempstr As String
'-- Program starts
Randomize Timer
Cls
Print "Password Creater"
Print "----------------"
Print
INPUT "How many characters per password? ", NumChar
INPUT "How many passwords do you want to generate? ", NumPass
Print
INPUT "Press Y to continue, or any key to quit: ", Ans$
'-- Generation begins
If UCase$(Ans$) = "Y" Then
'-- Create a temp file to hold passwords for comparison
'-- Note that this file is not readable using a text editor
Open "~temp.txt" For Random As #1 Len = NumChar + 2
'-- Begin creating passwords up to specified numbers
gNumCreated = 1
While gNumCreated <= NumPass
Tempstr = CreatePassword$(NumChar)
'-- Continue fetching new password until not a duplicate
While IsDuplicated(Tempstr) = 1
Tempstr = CreatePassword$(NumChar)
Wend
'-- If this point is reached, Tempstr contains a unique password.
'-- Assign it to the Password array
Put #1, gNumCreated, Tempstr
LOCATE 10, 1: Print "Number of Password Created: "; gNumCreated
gNumCreated = gNumCreated + 1
Wend
'-- Transfer passwords stored in ~temp.txt to Password.txt
'-- (which is more readable)
'-- ******* This is the final output file you want *******
Open "password.txt" For Output As #2
For x = 1 To NumPass
Get #1, x, s$
Print #2, s$
Next x
'-- Close all open files
Close
'-- Notify the user that the program is done
Beep
Print
Print
Print "Done...."
Print
Print "The passwords are stored in the Password.txt file in the current folder."
End If
Function CreatePassword$(mNumChar As Integer)
'-- Generate characters up to mNumChar
s$ = ""
For x% = 1 To mNumChar
'-- Randomly generate ASCII values
i% = Int(Rnd(1) * 48) + 74
'-- Exclude certain range of characters (like {!@# and etc.)
While (i% >= 58 And i% <= 64) Or (i% >= 91 And i% <= 96)
i% = Int(Rnd(1) * 48) + 74
Wend
s$ = s$ + Chr$(i%)
Next x%
'-- Return the created password
CreatePassword = s$
End Function
Function IsDuplicated%(mPwd As String)
'-- Loop through all the passwords already created so far
'-- (loop until gNumCreated - 1)
For x = 1 To gNumCreated - 1
'-- If mPwd happens to be equal to one of the passwords
'-- then exit out of this function and return 1
'-- to indicate that it is a duplicate
Get #1, x, s$
If mPwd = s$ Then
IsDuplicated = 1
Exit Function
End If
Next x
'-- If this point is reached mPwd is unique, so return 0
'-- to indicate that it is a valid password
IsDuplicated = 0
End Function
This creates a list of randomly generated unique passwords, and places them all in a Password.txt file in the current folder.
Keywords: kbinfo KB199323