Jump to content
Sign in to follow this  
SuperFletch

Confirming a password in a GUI

Recommended Posts

Hi Folks,

I've had a good look through the GUI and General forums and I'm sure this will be explained in another post but I can't find it.

If someone could point me to the right bit of the helpfile, an old dicussion board or post code that would be great.

I use a GUI to get the end user to input a u/n & p/w for a particular application which are stored as variables for use later on in the program.

I need to be sure they enter the correct details in the p/w box or my program will fail when it opens the app later. I basically want to make them enter the details of the password twice so that if they enter it incorrectly this is flagged with a message and asks them to try again.

It's obviously possible, but I just can't think how to do it. :)

TIA,

Share this post


Link to post
Share on other sites

I don't usually like to do this, but I'm bored so I wrote this up.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>

Opt('GUIOnEventMode', 1)

Global $sUsername, $sPassword
Global $iPasswordStyle = BitOR($ES_LEFT, $ES_AUTOHSCROLL, $ES_PASSWORD)

$gui = GUICreate('Login', 200, 100)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_Handler') ; 
GUICtrlCreateLabel('Username:', 5, 5, 90, 20, $SS_CENTERIMAGE)
$inUsername = GUICtrlCreateInput('', 105, 5, 90, 20)
GUICtrlCreateLabel('Password:', 5, 25, 90, 20, $SS_CENTERIMAGE)
$inPassword = GUICtrlCreateInput('', 105, 25, 90, 20, $iPasswordStyle)
GUICtrlCreateLabel('Confirm Password:', 5, 45, 90, 20, $SS_CENTERIMAGE)
$inPassConfirm = GUICtrlCreateInput('', 105, 45, 90, 20, $iPasswordStyle)
$btContinue = GUICtrlCreateButton('Continue', 135, 70, 60, 25)
    GUICtrlSetOnEvent(-1, '_Handler')
GUISetState()

While 1
    Sleep(1)
WEnd

Func _Handler()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btContinue
            $sUsername = GUICtrlRead($inUsername)
            $sPassword = GUICtrlRead($inPassword)
            If $sPassword = GUICtrlRead($inPassConfirm) Then
                ; Good to go, close the GUI or whatever you want to do here.
            Else
                MsgBox(0,'', 'Passwords do not match.')
                Global $sUsername, $sPassword
            EndIf
    EndSwitch
EndFunc

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  

×
×
  • Create New...