Jump to content
helmar

Code / GUI - is the a better way to do this?

Recommended Posts

helmar

It has been a while since I wrote code for "others" and I was hoping someone could take a few minutes and see if I am doing this both efficiently and decently.  I also want to ask about clearing out the inputted values from memory - how best to do that?

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <Crypt.au3>
Opt('MustDeclareVars', 1)

Global $ProgName = "Create Password", $EnterNicknameLabel, $NicknameEdit, $EnterMasterPasswordLabel, $MasterPasswordEdit, $AccountPasswordLabel, $AccountPasswordEdit, $ButtonOk, $ButtonStartOver, $ButtonCancel, $msg



GUICreate($ProgName, 313, 200, -1, -1)  ;title, height, width, left (-1 means centered), top (-1 means centered)
    $EnterNicknameLabel = GUICtrlCreateLabel("Nickname:", 20, 10)
    $NicknameEdit = GUICtrlCreateInput("", 20, 30, 270, 20, $ES_PASSWORD)
    $EnterMasterPasswordLabel = GUICtrlCreateLabel("Master password:", 20, 55)
    $MasterPasswordEdit = GUICtrlCreateInput("", 20, 75, 270, 20, $ES_PASSWORD)
    $AccountPasswordLabel = GUICtrlCreateLabel("Account password:", 20, 100)
    GUICtrlSetState($AccountPasswordLabel,$GUI_HIDE)
    $AccountPasswordEdit = GUICtrlCreateInput("", 20, 120, 270, 20, $ES_READONLY)
    GUICtrlSetState($AccountPasswordEdit,$GUI_HIDE)
    $ButtonOk = GUICtrlCreateButton("&OK", 20, 150, 120, 25)
    $ButtonStartOver = GUICtrlCreateButton("&Start Over", 20, 150, 120, 25)
    GUICtrlSetState($ButtonStartOver, $GUI_HIDE)
    $ButtonCancel = GUICtrlCreateButton("&Cancel", 170, 150, 120, 25)
GUISetState()

While 1 ; Run the GUI until the window is closed
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

        Case $msg = $ButtonOk

            If GUICtrlRead($NicknameEdit) = "" then ;no nickname entered
                MsgBox(0, $ProgName, "Please enter a nickname.")
                ContinueLoop

            endif

            If GUICtrlRead($MasterPasswordEdit) = "" then ;no password entered
                MsgBox(0, $ProgName, "Please enter a master password.")
                ContinueLoop

            endif

            GUICtrlSetData($AccountPasswordEdit,CreatePasswd(GUICtrlRead($MasterPasswordEdit),GUICtrlRead($NicknameEdit)))
            GUICtrlSetData($MasterPasswordEdit, "")
            GUICtrlSetData($NicknameEdit, "")
            GUICtrlSetState($NicknameEdit,$GUI_HIDE)
            GUICtrlSetState($MasterPasswordEdit,$GUI_HIDE)
            GUICtrlSetState($AccountPasswordLabel,$GUI_SHOW)
            GUICtrlSetState($AccountPasswordEdit,$GUI_SHOW)
            GUICtrlSetState($ButtonOk, $GUI_HIDE)
            GUICtrlSetState($ButtonStartOver, $GUI_SHOW)
        Case $msg = $ButtonStartOver

            GUICtrlSetState($AccountPasswordLabel,$GUI_HIDE)
            GUICtrlSetState($AccountPasswordEdit,$GUI_HIDE)
            GUICtrlSetState($ButtonStartOver, $GUI_HIDE)
            GUICtrlSetState($MasterPasswordEdit,$GUI_SHOW)
            GUICtrlSetState($NicknameEdit,$GUI_SHOW)
            GUICtrlSetState($ButtonOk, $GUI_SHOW)
            GUICtrlSetState($NicknameEdit, $GUI_FOCUS)
        Case $msg = $ButtonCancel

            ExitLoop

    EndSelect

WEnd



GUIDelete();    ; will return 1

Func CreatePasswd($secret, $mnemonic)    ;this is just dummy function
;actual function does ensure 8 char password or greater is created
;the process isn't included here for brevity
    Return $secret & $mnemonic
EndFunc

The actual password creation function is not included here, but does take into account complexity requirements, and min length of 8, and including special characters.

Thanks in advance for all comments / thoughts / ideas.

Edited by helmar
explain things better

Share this post


Link to post
Share on other sites
Starstar

It has been a while since I wrote code for "others"

Good you are going to help others.............

i tried your password Creator ........But you don't think this is useless... if you are going to guide those people who does not know to create a strong or very strong password then add something difficult to hack....suppose my nick name was jon and master password was 123 and your password creator is going to advise me use "123jon" as a password....and this password will be rejected by many Forum websites because it length is not so good it should be 8.

Edit:::

your script must be able to detect password length......that should be 8 or more

At-least one alphabet must be capital in nickname or in master password.

after applying tricks like this it make sense that the script is for helping user to create a strong or very strong password.  

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
helmar

Good you are going to help others.............

    after applying tricks like this it make sense that the script is for helping user to create a strong or very strong password.  

The actual "CreatePasswd" function does do what you recommend.  I wrote this code so that I could have that function stand outside of the GUI logic.  An example of resulting password would be "1_YXmLZv".  Numbers, mixed case, special characters, 8 chars.  I didn't include the actual function, both for brevity, and for ease of review.  My questions are regarding GUI concepts (was I efficient) and clearing inputted values from memory (if possible).

Share this post


Link to post
Share on other sites
Starstar
$NicknameEdit = Null
$MasterPasswordEdit = Null

After using the input variable just set them to null ........Like above example. Values will be automatically remove from random access memory.

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

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

×