Sign in to follow this  
Followers 0
Azazash

Login Prompt and Hidden Windows

4 posts in this topic

Hi,

Can anyone give me some pointers as to why my code that ive written behaves as it does?

Im trying to create a login prompt for an application, that simply pops up with the login prompt first, then when authenticated hides the login prompt and shows the main screen?

Here is my code that ive got so far. It is just the basic stuff witht he data on the main application pages stripped out as they are running fine.

#Region - Includes, Globals, Variables and Options
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
#EndRegion - Includes, Globals, Variables and Options

#Region - Login Prompt
$LoginForm = GUICreate("Login", 257, 115, -1, -1, BitOR($WS_SYSMENU, $WS_DLGFRAME, $WS_POPUP, $WS_CLIPSIBLINGS))
$loginpassed = 0
GUISetOnEvent($GUI_EVENT_CLOSE, "LoginFormClose")
$Username = GUICtrlCreateInput("", 16, 16, 225, 21)
$error = ''
$password = "support"
$i = 0
$Login = GUICtrlCreateButton("Login", 192, 80, 50, 25, 0)
GUICtrlSetOnEvent(-1, "LoginClick")
$Cancel = GUICtrlCreateButton("Cancel", 16, 80, 50, 25, 0)
GUICtrlSetOnEvent(-1, "CancelClick")
GUISetState(@SW_SHOW)
#EndRegion - Login Prompt

#Region - Main Form Design
$LST = GUICreate("Lexacom Support Tools", 385, 303, 327, 192)
GUISetFont(8, 400, 0, "Dax-Medium")
$SupportTools = GUICtrlCreateTab(0, 0, 380, 264)
GUICtrlSetFont(-1, 9, 400, 0, "Century Gothic")
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUISetState(@SW_SHOW)
#EndRegion - Main Form Design 

#Region - Run Loop
While 1
    Sleep(200)
WEnd
#EndRegion - Run Loop

#Region - Login Functions
Func LoginClick()
    $uname = GUICtrlRead($Username)
    If $uname = $password Then
        $loginpassed = 1
        GUISetState(@SW_HIDE)
    Else
        $i = $i + 1
        $count = 3 - $i
        If $count = 1 Then
            GUICtrlSetData($error, "")
            $error = GUICtrlCreateLabel("Incorrect Login Attempt. You Have " & $count & " Try Left", 15, 40)
        Else
            GUICtrlSetData($error, "")
            $error = GUICtrlCreateLabel("Incorrect Login Attempt. You Have " & $count & " Tries Left", 15, 40)
        EndIf
        If $i = 3 Then
            GUICtrlSetData($error, "")
            $error = GUICtrlCreateLabel("Too Many Login Attempts Exiting...", 15, 40)
            Sleep(1000)
            Exit
        EndIf
    EndIf
EndFunc  ;==>LoginClick

Func CancelClick()
    Exit
EndFunc  ;==>CancelClick

Func LoginFormClose()
    Exit
EndFunc  ;==>LoginFormClose
#EndRegion - Login Functions

#Region - Main Functions
Func LSTClose()
    Exit         
EndFunc   ;==>LSTClose
#EndRegion

I would appreciate any assistance as ive been pulling my hair out about this for 4 hours so far ...

Share this post


Link to post
Share on other sites



BUMP

Anyone know?

Share this post


Link to post
Share on other sites

It's hard to help you when you don't say what the problem is, but to begin with you should change your "GUISetState(@SW_HIDE)" to GUISetState(@SW_HIDE, $LoginForm) since you said you wanted to hide the login

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Sorry for the delay in response, i havent been able to continue with this until today.

What im trying to achieve is a login prompt that a user has to just type a login into, which upon successful entry, hides the login prompt then displays the main form.

Whats happening with the code at the moment is that upon successful login it does hide the log in form, but wont show the main form. When ive done a trace it stops at the end of the function and does nothing.

Is there anyway to get the code to go back to a specific point in the code and to contine from there? or do i need to call another function or something to get it to continue?

this is what i have so far.

#include <GUIConstants.au3>
#include <array.au3>
#include <File.au3>
Opt("GUIOnEventMode", 1)

$ScriptDir = @ScriptDir

;~ Development Environment Variables
$systemdir = $ScriptDir & "\Windows\System32\"
$windir = $ScriptDir & "\Windows\"
;~ Live Environment Variables
;~ $systemdir = @SystemDir
;~ $windir = @WindowsDir

    #Region - Login Prompt
    $LoginForm = GUICreate("Login", 257, 115, -1, -1, BitOR($WS_SYSMENU, $WS_DLGFRAME, $WS_POPUP, $WS_CLIPSIBLINGS))
    $loginpassed = 0
    $password = "support";simple password for testing purposes
    $i = 0
    HotKeySet("{ENTER}", "LoginClick")
    GUICtrlCreateLabel("Please enter your Login ID to continue.", 16, 16, 225, 20, $SS_CENTER)
    GUISetOnEvent($GUI_EVENT_CLOSE, "LoginFormClose")
    $Username = GUICtrlCreateInput("", 16, 42, 225, 21)
    $Login = GUICtrlCreateButton("Login", 192, 80, 50, 25, 0)
    GUICtrlSetOnEvent(-1, "LoginClick")
    $error = GUICtrlCreateLabel("", 71, 78, 116, 30, BitOR($SS_CENTER, $SS_SUNKEN))
    $Cancel = GUICtrlCreateButton("Cancel", 16, 80, 50, 25, 0)
    GUICtrlSetOnEvent(-1, "CancelClick")
    GUISetState(@SW_SHOW,$LoginForm)
    WinWaitClose("Login")
    #EndRegion - Login Prompt
    
    
    #Region - Main Form Design
    $LST = GUICreate("Lexacom Support Tools", 385, 303, 327, 192)
    GUISetFont(8, 400, 0, "Dax-Medium")
    $SupportTools = GUICtrlCreateTab(0, 0, 380, 264)
    GUICtrlSetFont(-1, 9, 400, 0, "Century Gothic")
    GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
    $ExitButton = GUICtrlCreateButton("&Exit", 8, 272, 75, 25, 0)
    GUICtrlSetFont(-1, 9, 400, 0, "Century Gothic")
    GUICtrlSetOnEvent(-1, "ExitButtonclick")
    GUISetOnEvent($GUI_EVENT_CLOSE, "ExitButtonclick")
    GUISetState(@SW_SHOW,$LST)
    #EndRegion - Main Form Design

While 1
    Sleep(100)
WEnd

    #Region - Login Functions
    Func LoginClick()
        $uname = GUICtrlRead($Username)
        If $uname = $password Then
            $loginpassed = 1
            GUISetState(@SW_HIDE, $LoginForm)
        Return
        Else
            $i = $i + 1
            $count = 3 - $i
            If $count = 1 Then
                GUICtrlSetData($error, "")
                $error = GUICtrlCreateLabel("Incorrect Login." & @CRLF & "You Have " & $count & " Try Left", 71, 78, 116, 30, BitOR($SS_CENTER, $SS_SUNKEN))
                Sleep(1000)
                GUICtrlSetData($Username, "")
                GUICtrlSetData($error, "")
            Else
                GUICtrlSetData($error, "")
                $error = GUICtrlCreateLabel("Incorrect Login." & @CRLF & "You Have " & $count & " Tries Left", 71, 78, 116, 30, BitOR($SS_CENTER, $SS_SUNKEN))
                Sleep(1000)
                GUICtrlSetData($Username, "")
                GUICtrlSetData($error, "")
            EndIf
            If $i = 3 Then
                GUICtrlSetData($error, "")
                $error = GUICtrlCreateLabel("Too Many Attempts " & @CRLF & "Exiting...", 71, 78, 116, 30, BitOR($SS_CENTER, $SS_SUNKEN))
                Sleep(1000)
                Exit
            EndIf
        EndIf
    EndFunc  ;==>LoginClick
    Func CancelClick()
        Exit
    EndFunc  ;==>CancelClick
    Func LoginFormClose()
        Exit
    EndFunc  ;==>LoginFormClose
    Func ExitButtonclick()
        $ExitButton = $GUI_EVENT_CLOSE
    Exit
    EndFunc  ;==>ExitButtonclick
    #EndRegion - Login Functions
    
    #Region - Main Functions
    Func LSTClose()
        Exit
    EndFunc  ;==>LSTClose
    #EndRegion - Main Functions
Edited by Azazash

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