Sign in to follow this  
Followers 0
slayed

Don't allow click out

14 posts in this topic

#1 ·  Posted (edited)

I have coded in other simple languages and have some experience in PHP but can't seem to figure out how to do this. I want to create a user input pop up window that requires a password before the user can do anything else like click out and go to a different window. I just used the script they provided because i'm too lazy to code from scratch. Can you tell me what else I need? I would also like to disable keys that would bypass this pop-up, i.e. ctrl+alt+del or alt+f4. I basically want to be able to run this when i leave my computer alone instead of logging out

$bLoop = 1
While $bLoop = 1
    $text = InputBox("Unlock the Computer", "Type in the password and click OK")
    If @error = 1 Then
        MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
    Else
       ; They clicked OK, but did they type the right thing?
        If $text <> "password" Then
            MsgBox(4096, "Error", "You typed in the wrong thing - try again!")
        Else
            $bLoop = 0   ; Exit the loop - ExitLoop would have been an alternative too :)
        EndIf
    EndIf
WEnd

; Print the success message
MsgBox(4096,"AutoIt Example", "Welcome Back!")
Edited by slayed

Share this post


Link to post
Share on other sites



As for the look of your script, I suggest you take a look at Bert's _LoginBox() :

#include <GUIConstants.au3>
$ret = _LoginBox("Enter Credentials", "Please enter you username and password", "username", "password", -1, -1, -1, -1, -1, 2000)
MsgBox(0, "Returned", "Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended)
If Not @error Then
    MsgBox(0, "Credentails Returned", "Username: " & $ret[0] & @CRLF & "Password: " & $ret[1])
EndIf
;===============================================================================
;
; Function Name:        _LoginBox
; Description::            Create a basic login box with Username, Password, and a prompt.
; Parameter(s):            Title        - [Required]
;                                        - The title of the Form
;                        Prompt        - [Required]
;                                        - The prompt for the user
;                        uDefault    - [Optional] - Default Value = ""
;                                        - The default vaue for the Username Input
;                        pDefault    - [Optional] - Default Value = ""
;                                        - The default vaue for the Password Input
;                        bBlank        - [Optional] - Default Value = True
;                                        - Set whether the password or username can be blank.
;                                            - True = Cannot be blank
;                                            - False = Blank is allowed
;                        Width        - [Optional] - Default Value = 250
;                                        - The width of the Login Box
;                        Height        - [Optional] - Default Value = 130
;                                        - The height of the Login Box
;                        Left        - [Optional] - Default Value = Auto Center Screen
;                                        - The positioning (Left) of the Login Box
;                        Top            -  [Optional] - Default Value = Auto Center Screen
;                                        - The positioning (Top) of the Login Box
;                        Timeout        - [Optional] - Default Value = -1 (No Timeout)
;                                        - The timeout of the Login Box
;                        ShowError    - [Optional] - Default Value = 0 (Do Not Show)
;                                        - Sets whether prompts are displayed to the user with timeout.
;                                            - 0 = Do not Show
;                                            - 1 = Show
; Requirement(s):        none
; Return Value(s):        Success:
;                            - Sets @error to 1 (@extended = 0 EXCEPT when bBlank = True, and both fields are not blank)
;                            - Returns a 1D array with the following
;                                - [0] = Username
;                                - [1] = Password
;                        Failure
;                            - Sets @error to 0
;                            - Sets @extended to:
;                                - 1 - The Cancel or Exit Button was Pressed
;                                - 2 - The Login Box Timed Out.
; Author(s):            Brett Francis (exodus.is.me@hotmail.com)
; Note(s):                 none
;
;===============================================================================

Func _LoginBox($title, $prompt, $uDefault = "", $pDefault = "", $bBlank = True, $width = 250, $height = 130, $left = -1, $top = -1, $timeout = -1, $ShowError = 0)
    Select
        Case $uDefault = -1
            $uDefault = ""
            ContinueCase
        Case $pDefault = -1
            $pDefault = ""
            ContinueCase
        Case $bBlank = -1
            $bBlank = True
            ContinueCase
        Case $width = -1
            $width = 250
            ContinueCase
        Case $height = -1
            $height = 130
            ContinueCase
        Case $left = -1
            $left = (@DesktopWidth / 2) - ($width / 2)
            ContinueCase
        Case $top = -1
            $top = (@DesktopHeight / 2) - ($height / 2)
            ContinueCase
    EndSelect
    
    Local $retarr[2]
    
    $gui = GUICreate($title, $width, $height, $left, $top)
    $username = GUICtrlCreateInput($uDefault, 72, 42, 173, 21)
    $password = GUICtrlCreateInput($pDefault, 72, 70, 173, 21, $ES_PASSWORD)
    $okbtn = GUICtrlCreateButton("&OK", 90, 96, 75, 25, 0)
    $cancelbtn = GUICtrlCreateButton("&Cancel", 171, 96, 75, 25, 0)
    $Label1 = GUICtrlCreateLabel("Password:", 4, 72, 62, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Username:", 4, 44, 64, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel($prompt, 4, 4, 201, 17)
    GUICtrlSetState($okbtn, $GUI_DEFBUTTON)
    GUISetState(@SW_SHOW)
    $time = TimerInit()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                $case = 0
                ExitLoop
            Case $msg = $okbtn
                If $bBlank = False Then
                    $case = 1
                    ExitLoop
                Else
                    If GUICtrlRead($username) <> "" And GUICtrlRead($password) <> "" Then
                        $case = 1
                        ExitLoop
                    Else
                        Select
                            Case GUICtrlRead($username) = "" And GUICtrlRead($password) = ""
                                MsgBox(16, "Error!", "Username and Password cannot be blank!")
                            Case GUICtrlRead($password) = ""
                                MsgBox(16, "Error!", "Password cannot be blank!")
                                GUICtrlSetState($password, $GUI_FOCUS)
                            Case GUICtrlRead($username) = ""
                                MsgBox(16, "Error!", "Username cannot be blank!")
                                GUICtrlSetState($username, $GUI_FOCUS)
                        EndSelect
                    EndIf
                EndIf
            Case $msg = $cancelbtn
                $case = 0
                ExitLoop
            Case TimerDiff($time) > $timeout And $timeout
                If $bBlank = False Then
                    $case = 2
                    ExitLoop
                Else
                    Select
                        Case GUICtrlRead($username) = "" And GUICtrlRead($password) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!")
                        Case GUICtrlRead($password) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "Password cannot be blank!")
                                GUICtrlSetState($password, $GUI_FOCUS)
                            EndIf
                        Case GUICtrlRead($username) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "Username cannot be blank!")
                                GUICtrlSetState($username, $GUI_FOCUS)
                            EndIf
                        Case Else
                            If GUICtrlRead($username) <> "" And GUICtrlRead($password) <> "" Then
                                $case = 3
                                ExitLoop
                            EndIf
                    EndSelect
                EndIf
        EndSelect
    WEnd
    
    If $case = 0 Then;Cancel/Exit Button Pressed
        GUIDelete($gui)
        Return SetError(0, 1, 0)
    ElseIf $case = 2 Then;Timed Out
        GUIDelete($gui)
        Return SetError(0, 2, 0)
    ElseIf $case = 1 Then;Ok Pressed
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return SetError(1, 0, $retarr)
    ElseIf $case = 3 Then;Username Fields Not Blank, Timeout reached
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return SetError(1, 1, $retarr)
    EndIf
EndFunc  ;==>_LoginBox

Share this post


Link to post
Share on other sites

just to double check before i run that is

username: "username"

and

password: "password

w/o the quotes?

Share this post


Link to post
Share on other sites

just to double check before i run that is

username: "username"

and

password: "password

w/o the quotes?

huh?

This is how you use it:

_LoginBox("Title", "Prompt", "username", "password",...)

If your username is IAmTheWeasel and your password is eatmyshorts, then this is what you should use:

_LoginBox("Title", "Prompt", "IAmTheWeasel", "eatmyshorts",...)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

With this exact code the window pops up and then is replaced by a window titled "returned" that says i have an error in my code, then finally i get a window entitled "credentials returned". underneath it says

username: username

password: password

#include <GUIConstants.au3>
$ret = _LoginBox("Enter Credentials", "Please enter you username and password", "username", "password", -1, -1, -1, -1, -1, 2000)
MsgBox(0, "Returned", "Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended)
If Not @error Then
    MsgBox(0, "Credentails Returned", "Username: " & $ret[0] & @CRLF & "Password: " & $ret[1])
EndIf
;===============================================================================
;
; Function Name:        _LoginBox
; Description::         Create a basic login box with Username, Password, and a prompt.
; Parameter(s):         Title       - [Required]
;                                       - The title of the Form
;                       Prompt      - [Required]
;                                       - The prompt for the user
;                       uDefault    - [Optional] - Default Value = ""
;                                       - The default vaue for the Username Input
;                       pDefault    - [Optional] - Default Value = ""
;                                       - The default vaue for the Password Input
;                       bBlank      - [Optional] - Default Value = True
;                                       - Set whether the password or username can be blank.
;                                           - True = Cannot be blank
;                                           - False = Blank is allowed
;                       Width       - [Optional] - Default Value = 250
;                                       - The width of the Login Box
;                       Height      - [Optional] - Default Value = 130
;                                       - The height of the Login Box
;                       Left        - [Optional] - Default Value = Auto Center Screen
;                                       - The positioning (Left) of the Login Box
;                       Top         -  [Optional] - Default Value = Auto Center Screen
;                                       - The positioning (Top) of the Login Box
;                       Timeout     - [Optional] - Default Value = -1 (No Timeout)
;                                       - The timeout of the Login Box
;                       ShowError   - [Optional] - Default Value = 0 (Do Not Show)
;                                       - Sets whether prompts are displayed to the user with timeout.
;                                           - 0 = Do not Show
;                                           - 1 = Show
; Requirement(s):       none
; Return Value(s):      Success:
;                           - Sets @error to 1 (@extended = 0 EXCEPT when bBlank = True, and both fields are not blank)
;                           - Returns a 1D array with the following
;                               - [0] = Username
;                               - [1] = Password
;                       Failure
;                           - Sets @error to 0
;                           - Sets @extended to:
;                               - 1 - The Cancel or Exit Button was Pressed
;                               - 2 - The Login Box Timed Out.
; Author(s):            Brett Francis (exodus.is.me@hotmail.com)
; Note(s):               none
;
;===============================================================================

Func _LoginBox($title, $prompt, $uDefault = "myusername", $pDefault = "mypassword", $bBlank = True, $width = 250, $height = 130, $left = -1, $top = -1, $timeout = -1, $ShowError = 0)
    Select
        Case $uDefault = -1
            $uDefault = ""
            ContinueCase
        Case $pDefault = -1
            $pDefault = ""
            ContinueCase
        Case $bBlank = -1
            $bBlank = True
            ContinueCase
        Case $width = -1
            $width = 250
            ContinueCase
        Case $height = -1
            $height = 130
            ContinueCase
        Case $left = -1
            $left = (@DesktopWidth / 2) - ($width / 2)
            ContinueCase
        Case $top = -1
            $top = (@DesktopHeight / 2) - ($height / 2)
            ContinueCase
    EndSelect
   
    Local $retarr[2]
   
    $gui = GUICreate($title, $width, $height, $left, $top)
    $username = GUICtrlCreateInput($uDefault, 72, 42, 173, 21)
    $password = GUICtrlCreateInput($pDefault, 72, 70, 173, 21, $ES_PASSWORD)
    $okbtn = GUICtrlCreateButton("&OK", 90, 96, 75, 25, 0)
    $cancelbtn = GUICtrlCreateButton("&Cancel", 171, 96, 75, 25, 0)
    $Label1 = GUICtrlCreateLabel("Password:", 4, 72, 62, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Username:", 4, 44, 64, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel($prompt, 4, 4, 201, 17)
    GUICtrlSetState($okbtn, $GUI_DEFBUTTON)
    GUISetState(@SW_SHOW)
    $time = TimerInit()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                $case = 0
                ExitLoop
            Case $msg = $okbtn
                If $bBlank = False Then
                    $case = 1
                    ExitLoop
                Else
                    If GUICtrlRead($username) <> "" And GUICtrlRead($password) <> "" Then
                        $case = 1
                        ExitLoop
                    Else
                        Select
                            Case GUICtrlRead($username) = "" And GUICtrlRead($password) = ""
                                MsgBox(16, "Error!", "Username and Password cannot be blank!")
                            Case GUICtrlRead($password) = ""
                                MsgBox(16, "Error!", "Password cannot be blank!")
                                GUICtrlSetState($password, $GUI_FOCUS)
                            Case GUICtrlRead($username) = ""
                                MsgBox(16, "Error!", "Username cannot be blank!")
                                GUICtrlSetState($username, $GUI_FOCUS)
                        EndSelect
                    EndIf
                EndIf
            Case $msg = $cancelbtn
                $case = 0
                ExitLoop
            Case TimerDiff($time) > $timeout And $timeout
                If $bBlank = False Then
                    $case = 2
                    ExitLoop
                Else
                    Select
                        Case GUICtrlRead($username) = "" And GUICtrlRead($password) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!")
                        Case GUICtrlRead($password) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "Password cannot be blank!")
                                GUICtrlSetState($password, $GUI_FOCUS)
                            EndIf
                        Case GUICtrlRead($username) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "Username cannot be blank!")
                                GUICtrlSetState($username, $GUI_FOCUS)
                            EndIf
                        Case Else
                            If GUICtrlRead($username) <> "" And GUICtrlRead($password) <> "" Then
                                $case = 3
                                ExitLoop
                            EndIf
                    EndSelect
                EndIf
        EndSelect
    WEnd
   
    If $case = 0 Then;Cancel/Exit Button Pressed
        GUIDelete($gui)
        Return SetError(0, 1, 0)
    ElseIf $case = 2 Then;Timed Out
        GUIDelete($gui)
        Return SetError(0, 2, 0)
    ElseIf $case = 1 Then;Ok Pressed
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return SetError(1, 0, $retarr)
    ElseIf $case = 3 Then;Username Fields Not Blank, Timeout reached
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return SetError(1, 1, $retarr)
    EndIf
EndFunc;==>_LoginBox
Edited by slayed

Share this post


Link to post
Share on other sites

you dont actually run that script, you include it. :)

Share this post


Link to post
Share on other sites

you dont actually run that script, you include it. :)

include it in what... i'm new as you can see by when i joined

Share this post


Link to post
Share on other sites

include it in what... i'm new as you can see by when i joined

Look at the help file, it will tell you everything you need to know to get started search for #Include

Share this post


Link to post
Share on other sites

No, there's no need to include it that way. Just put it at the end of your script. Here's an example:

#include <GUIConstants.au3>
While 1
    $ret = _LoginBox("Enter Credentials", "Please enter you username and password", "username", "password", -1, -1, -1, -1, -1,Default)
    If @error Then
        If $ret[0]="I am the weasel" AND $ret[1]="eatmyshorts" Then
            MsgBox(0,"","Welcome back!")
            ExitLoop
        Else
            MsgBox(0,"","Wrong password")
        EndIf
    Else
        MsgBox(0,"Error","You pressed cancel")
    EndIf
WEnd
;Once your password is correct, you do your stuff from this point on.


Func _LoginBox($title, $prompt, $uDefault = "myusername", $pDefault = "mypassword", $bBlank = True, $width = 250, $height = 130, $left = -1, $top = -1, $timeout = -1, $ShowError = 0)
    Select
        Case $uDefault = -1
            $uDefault = ""
            ContinueCase
        Case $pDefault = -1
            $pDefault = ""
            ContinueCase
        Case $bBlank = -1
            $bBlank = True
            ContinueCase
        Case $width = -1
            $width = 250
            ContinueCase
        Case $height = -1
            $height = 130
            ContinueCase
        Case $left = -1
            $left = (@DesktopWidth / 2) - ($width / 2)
            ContinueCase
        Case $top = -1
            $top = (@DesktopHeight / 2) - ($height / 2)
            ContinueCase
    EndSelect
   
    Local $retarr[2]
   
    $gui = GUICreate($title, $width, $height, $left, $top)
    $username = GUICtrlCreateInput($uDefault, 72, 42, 173, 21)
    $password = GUICtrlCreateInput($pDefault, 72, 70, 173, 21, $ES_PASSWORD)
    $okbtn = GUICtrlCreateButton("&OK", 90, 96, 75, 25, 0)
    $cancelbtn = GUICtrlCreateButton("&Cancel", 171, 96, 75, 25, 0)
    $Label1 = GUICtrlCreateLabel("Password:", 4, 72, 62, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Username:", 4, 44, 64, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel($prompt, 4, 4, 201, 17)
    GUICtrlSetState($okbtn, $GUI_DEFBUTTON)
    GUISetState(@SW_SHOW)
    $time = TimerInit()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                $case = 0
                ExitLoop
            Case $msg = $okbtn
                If $bBlank = False Then
                    $case = 1
                    ExitLoop
                Else
                    If GUICtrlRead($username) <> "" And GUICtrlRead($password) <> "" Then
                        $case = 1
                        ExitLoop
                    Else
                        Select
                            Case GUICtrlRead($username) = "" And GUICtrlRead($password) = ""
                                MsgBox(16, "Error!", "Username and Password cannot be blank!")
                            Case GUICtrlRead($password) = ""
                                MsgBox(16, "Error!", "Password cannot be blank!")
                                GUICtrlSetState($password, $GUI_FOCUS)
                            Case GUICtrlRead($username) = ""
                                MsgBox(16, "Error!", "Username cannot be blank!")
                                GUICtrlSetState($username, $GUI_FOCUS)
                        EndSelect
                    EndIf
                EndIf
            Case $msg = $cancelbtn
                $case = 0
                ExitLoop
            Case TimerDiff($time) > $timeout And $timeout
                If $bBlank = False Then
                    $case = 2
                    ExitLoop
                Else
                    Select
                        Case GUICtrlRead($username) = "" And GUICtrlRead($password) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!")
                        Case GUICtrlRead($password) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "Password cannot be blank!")
                                GUICtrlSetState($password, $GUI_FOCUS)
                            EndIf
                        Case GUICtrlRead($username) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "Username cannot be blank!")
                                GUICtrlSetState($username, $GUI_FOCUS)
                            EndIf
                        Case Else
                            If GUICtrlRead($username) <> "" And GUICtrlRead($password) <> "" Then
                                $case = 3
                                ExitLoop
                            EndIf
                    EndSelect
                EndIf
        EndSelect
    WEnd
   
    If $case = 0 Then;Cancel/Exit Button Pressed
        GUIDelete($gui)
        Return SetError(0, 1, 0)
    ElseIf $case = 2 Then;Timed Out
        GUIDelete($gui)
        Return SetError(0, 2, 0)
    ElseIf $case = 1 Then;Ok Pressed
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return SetError(1, 0, $retarr)
    ElseIf $case = 3 Then;Username Fields Not Blank, Timeout reached
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return SetError(1, 1, $retarr)
    EndIf
EndFunc;==>_LoginBox

Of course that all this does is check if you entered the right username and password. To not allow click out, you'll have to figure out a way. You could get a list of existing windows and disable them all. After the user has entered the password, you re-enable them.

Share this post


Link to post
Share on other sites

Mouse trap? lol

Share this post


Link to post
Share on other sites

Mouse trap? lol

is that a joke or can i disallow the mouse to leave the box

Share this post


Link to post
Share on other sites

is that a joke or can i disallow the mouse to leave the box

No joke, look up _MouseTrap in the help file


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

is that a joke or can i disallow the mouse to leave the box

#include <GUIConstants.au3>
#include <Misc.au3>
While 1
    $ret = _LoginBox("Enter Credentials", "Please enter you username and password", "username", "password", -1, -1, -1, -1, -1,Default)
    
    If @error Then
        If $ret[0]="I am the weasel" AND $ret[1]="eatmyshorts" Then
            MsgBox(0,"","Welcome back!")
            ExitLoop
        Else
            MsgBox(0,"","Wrong password")
        EndIf
    Else
        MsgBox(0,"Error","You pressed cancel")
    EndIf
WEnd
;Once your password is correct, you do your stuff from this point on.



Func _LoginBox($title, $prompt, $uDefault = "myusername", $pDefault = "mypassword", $bBlank = True, $width = 250, $height = 130, $left = -1, $top = -1, $timeout = -1, $ShowError = 0)
    Select
        Case $uDefault = -1
            $uDefault = ""
            ContinueCase
        Case $pDefault = -1
            $pDefault = ""
            ContinueCase
        Case $bBlank = -1
            $bBlank = True
            ContinueCase
        Case $width = -1
            $width = 250
            ContinueCase
        Case $height = -1
            $height = 130
            ContinueCase
        Case $left = -1
            $left = (@DesktopWidth / 2) - ($width / 2)
            ContinueCase
        Case $top = -1
            $top = (@DesktopHeight / 2) - ($height / 2)
            ContinueCase
    EndSelect
   
    Local $retarr[2]
   
    $gui = GUICreate($title, $width, $height, $left, $top)
    $username = GUICtrlCreateInput($uDefault, 72, 42, 173, 21)
    $password = GUICtrlCreateInput($pDefault, 72, 70, 173, 21, $ES_PASSWORD)
    $okbtn = GUICtrlCreateButton("&OK", 90, 96, 75, 25, 0)
    $cancelbtn = GUICtrlCreateButton("&Cancel", 171, 96, 75, 25, 0)
    $Label1 = GUICtrlCreateLabel("Password:", 4, 72, 62, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Username:", 4, 44, 64, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel($prompt, 4, 4, 201, 17)
    GUICtrlSetState($okbtn, $GUI_DEFBUTTON)
    GUISetState(@SW_SHOW)
    $time = TimerInit()
    $coords = WinGetPos($GUI)
    _MouseTrap ($coords[0], $coords[1], $coords[0] + $coords[2], $coords[1] + $coords[3])
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                $case = 0
                ExitLoop
            Case $msg = $okbtn
                If $bBlank = False Then
                    $case = 1
                    ExitLoop
                Else
                    If GUICtrlRead($username) <> "" And GUICtrlRead($password) <> "" Then
                        $case = 1
                        ExitLoop
                    Else
                        Select
                            Case GUICtrlRead($username) = "" And GUICtrlRead($password) = ""
                                MsgBox(16, "Error!", "Username and Password cannot be blank!")
                            Case GUICtrlRead($password) = ""
                                MsgBox(16, "Error!", "Password cannot be blank!")
                                GUICtrlSetState($password, $GUI_FOCUS)
                            Case GUICtrlRead($username) = ""
                                MsgBox(16, "Error!", "Username cannot be blank!")
                                GUICtrlSetState($username, $GUI_FOCUS)
                        EndSelect
                    EndIf
                EndIf
            Case $msg = $cancelbtn
                $case = 0
                ExitLoop
            Case TimerDiff($time) > $timeout And $timeout
                If $bBlank = False Then
                    $case = 2
                    ExitLoop
                Else
                    Select
                        Case GUICtrlRead($username) = "" And GUICtrlRead($password) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!")
                        Case GUICtrlRead($password) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "Password cannot be blank!")
                                GUICtrlSetState($password, $GUI_FOCUS)
                            EndIf
                        Case GUICtrlRead($username) = ""
                            $time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "Username cannot be blank!")
                                GUICtrlSetState($username, $GUI_FOCUS)
                            EndIf
                        Case Else
                            If GUICtrlRead($username) <> "" And GUICtrlRead($password) <> "" Then
                                $case = 3
                                ExitLoop
                            EndIf
                    EndSelect
                EndIf
        EndSelect
    WEnd
   
    If $case = 0 Then;Cancel/Exit Button Pressed
        GUIDelete($gui)
        Return SetError(0, 1, 0)
    ElseIf $case = 2 Then;Timed Out
        GUIDelete($gui)
        Return SetError(0, 2, 0)
    ElseIf $case = 1 Then;Ok Pressed
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return SetError(1, 0, $retarr)
    ElseIf $case = 3 Then;Username Fields Not Blank, Timeout reached
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return SetError(1, 1, $retarr)
    EndIf
EndFunc;==>_LoginBox

Share this post


Link to post
Share on other sites

I'm not making the script for you, I don't have a lot of free time. :)

But instead of msgBoxes return errors/notifications in a label in the login window, if an error pops up you can freely move ur mouse again. ;D

Nahuel's code is good but there are loopholes. <_<

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