GaryFrost Posted December 14, 2004 Share Posted December 14, 2004 (edited) Not sure if anything has been posted like this, but found I needed a random password generator, thought I would share this little snippet. Improvements/comments welcome. Cleaned up the code and ran Tidy on it. Dim $PASSWORD = '', $MAXLENGTH = 8 For $MAXLENGTH = 8 To 36 Step 1 $PASSWORD = Random_Password($MAXLENGTH) MsgBox(4096, 'test', $PASSWORD) Next Exit Func Random_Password($MAXLENGTH) Dim $I = 0, $PASSWORD = '', $X = 0, $NUM_IN_PATTERN = 0, $SPECIAL_CHAR[7] ; create custom pattern $SPECIAL_CHAR[0] = '#' $SPECIAL_CHAR[1] = '$' $SPECIAL_CHAR[2] = '_' $SPECIAL_CHAR[3] = '+' $SPECIAL_CHAR[4] = '$' $SPECIAL_CHAR[5] = '-' $SPECIAL_CHAR[6] = '+' ;set the pattern to n characters long divisable by 4 ;in a random order Do $X = Round(Random(1, 4)) if ($X == 1) Then $PASSWORD = $PASSWORD & Chr(Random(Asc("a"), Asc("z") + 1)) elseif ($X == 2) Then $PASSWORD = $PASSWORD & Chr(Random(Asc("A"), Asc("Z") + 1)) elseif ($X == 3) Then $PASSWORD = $PASSWORD & Round(Random(0, 9)) elseif ($X == 4) Then $PASSWORD = $PASSWORD & $SPECIAL_CHAR[Round(Random(0, 3)) ] EndIf $NUM_IN_PATTERN = $NUM_IN_PATTERN + 1 Until $NUM_IN_PATTERN == $MAXLENGTH Return $PASSWORD EndFunc ;==>Random_Password Edited December 14, 2004 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
killaz219 Posted December 14, 2004 Share Posted December 14, 2004 (edited) Here a wrote up a smaller version of something like that to show you how you could trim it down Heres the code with an example MsgBox(0 , "Random Password", randompass("8")) Func RandomPass($length) Local $letter, $password For $i = 1 To $length $letter = Random(33, 126) $password = $password & Chr($letter) Next Return $password Endfunc Edit : And for the set char lengths you could do MsgBox(0 , "Random Password", randompass("8")) Func RandomPass($length) Local $letter, $password If $length < 9 then For $i = 1 To $length $letter = Random(33, 126) $password = $password & Chr($letter) Next Return $password Else Return "Length too long" Endif Endfunc Edited December 14, 2004 by killaz219 Link to comment Share on other sites More sharing options...
GaryFrost Posted December 14, 2004 Author Share Posted December 14, 2004 Thanks, that will work great. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
killaz219 Posted December 14, 2004 Share Posted December 14, 2004 (edited) Oops change the for $i = 0 to $length to for $i = 1 to $length Edited December 14, 2004 by killaz219 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now