Sign in to follow this  
Followers 0
SpookMeister

Basic Random Password generator

2 posts in this topic

I threw this together the other day, and while I'm sure there have been quite a few of these made already, maybe someone will find it usefull.

#include <GUIConstants.au3>
; 7 digit random password generator containing at least 1 each of
; Capital Letters, Lowercase Letters, and Numbers (no special chars)
; and coppies it to the clipboard

$text = MakePass()
GUICreate("PassGen", 260, 160)
$button_1 = GUICtrlCreateButton("Get Another Password", 25, 70, 200)
GUICtrlCreateLabel("Passwords are auto-coppied to the clipboard", 25, 120, 230)
GUISetFont(21)
$label_1 = GUICtrlCreateLabel($text, 70, 30, 150)


GUISetState()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $button_1 Then Update()
WEnd

; Update the GUI with a new password
Func Update()
    $text = MakePass()
    GUICtrlSetData($label_1, $text)
EndFunc  ;==>Update

Func MakePass()
; verify that password will have at least 1 of all three types of chars
    $GoodPass = 0
    Do
        $chkPass = rndLayout()
        If StringInStr($chkPass, "1") Then
            If StringInStr($chkPass, "2") Then
                If StringInStr($chkPass, "3") Then
                    $GoodPass = 1
                EndIf
            EndIf
        EndIf
    Until $GoodPass = 1
    
; Now that we have an acceptable layout for the password... populate it
    $password = ""
    For $x = 1 To 7
        $password = $password & Convert(StringMid($chkPass, $x, 1))
    Next
    ClipPut($password)
    Return $password
EndFunc  ;==>MakePass

Func Convert($cat)
; Numbers
    If $cat = 1 Then
        $val = Chr(Random(49, 57, 1))
    ; Capital Letters
    ElseIf $cat = 2 Then
        $val = Chr(Random(65, 90, 1))
    ; Lowercase Letters
    Else
        $val = Chr(Random(97, 122, 1))
    EndIf
    
; Subsitute undesired values to other values (personal preference)
    If $val = "l" Then $val = "x"
    If $val = "1" Then $val = "5"
    If $val = "i" Then $val = "y"
    If $val = "O" Then $val = "R"
    
    Return $val
EndFunc  ;==>Convert

; make a 7 char string of numbers 1 thru 3
Func rndLayout()
    $str = ""
    For $i = 1 To 7
        $str = $str & Random(1, 3, 1)
    Next
    Return $str
EndFunc  ;==>rndLayout

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites



very good,I am just using it,thank you!!!

I threw this together the other day, and while I'm sure there have been quite a few of these made already, maybe someone will find it usefull.

#include <GUIConstants.au3>
; 7 digit random password generator containing at least 1 each of
; Capital Letters, Lowercase Letters, and Numbers (no special chars)
; and coppies it to the clipboard

$text = MakePass()
GUICreate("PassGen", 260, 160)
$button_1 = GUICtrlCreateButton("Get Another Password", 25, 70, 200)
GUICtrlCreateLabel("Passwords are auto-coppied to the clipboard", 25, 120, 230)
GUISetFont(21)
$label_1 = GUICtrlCreateLabel($text, 70, 30, 150)
GUISetState()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $button_1 Then Update()
WEnd

; Update the GUI with a new password
Func Update()
    $text = MakePass()
    GUICtrlSetData($label_1, $text)
EndFunc ;==>Update

Func MakePass()
; verify that password will have at least 1 of all three types of chars
    $GoodPass = 0
    Do
        $chkPass = rndLayout()
        If StringInStr($chkPass, "1") Then
            If StringInStr($chkPass, "2") Then
                If StringInStr($chkPass, "3") Then
                    $GoodPass = 1
                EndIf
            EndIf
        EndIf
    Until $GoodPass = 1
    
; Now that we have an acceptable layout for the password... populate it
    $password = ""
    For $x = 1 To 7
        $password = $password & Convert(StringMid($chkPass, $x, 1))
    Next
    ClipPut($password)
    Return $password
EndFunc ;==>MakePass

Func Convert($cat)
; Numbers
    If $cat = 1 Then
        $val = Chr(Random(49, 57, 1))
; Capital Letters
    ElseIf $cat = 2 Then
        $val = Chr(Random(65, 90, 1))
; Lowercase Letters
    Else
        $val = Chr(Random(97, 122, 1))
    EndIf
    
; Subsitute undesired values to other values (personal preference)
    If $val = "l" Then $val = "x"
    If $val = "1" Then $val = "5"
    If $val = "i" Then $val = "y"
    If $val = "O" Then $val = "R"
    
    Return $val
EndFunc ;==>Convert

; make a 7 char string of numbers 1 thru 3
Func rndLayout()
    $str = ""
    For $i = 1 To 7
        $str = $str & Random(1, 3, 1)
    Next
    Return $str
EndFunc ;==>rndLayout

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0