Jump to content

select one gui


 Share

Recommended Posts

i've found a working login / create user function on the forums somewhere [i forget the exact link] and tried to throw together a script so you can select between create user and login existing user. the original only writes 1 user name / password, i'm wanting to be able to have multiple users, yet make it to where each time you create a user it will NOT overwrite the existing one.

but that's not the error i'm getting. it keeps giving me an error: "Incorrect number of parameters in function call.: _LoginBox()

here's the script

#include <guiconstants.au3>

hotkeyset ("{ESC}", "quit")
func quit()
    exit 0
EndFunc


guicreate ("Select one", 150, 100, -1, -1)
$new = guictrlcreatebutton ("New User", 20, 20, 70)
$exist = guictrlcreatebutton ("Existing User", 20, 50, 100)
guisetstate(@SW_SHOW)

while 1
    $msg = guigetmsg()
    if $msg = $new Then
            guidelete()
            _createuser()
    elseif $msg = $exist Then
            guidelete()
            _LoginBox()
    EndIf
    
WEnd


;===============================================================================
;  Creates a new user
;===============================================================================

Func _CreateUser()
    $gui = GUICreate("New User", 250, 130, -1, -1)
    $username = GUICtrlCreateInput("", 72, 42, 173, 21)
    $password = GUICtrlCreateInput("", 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("Please enter a username and password to " & @CRLF & "create a new user.", 4, 4, 201, 30)
    GUICtrlSetState($okbtn, $GUI_DEFBUTTON)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbtn
                Exit
            Case $msg = $okbtn
                If GUICtrlRead($username) <> "" And GUICtrlRead($password) <> "" Then
                    $plH = PluginOpen(@ScriptDir & "\MD5Hash.dll")
                    IniWrite(@ScriptDir & "\settings.ini", "USER", "USERNAME", GUICtrlRead($username))
                    IniWrite(@ScriptDir & "\settings.ini", "USER", "PASSWORD", MD5Hash (GUICtrlRead($password), 2, True))
                    PluginClose($plH)
                    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
        EndSelect
    WEnd
    GUIDelete($gui)
EndFunc ;==>_CreateUser

;===============================================================================
;
; 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 0 (@extended = 0 See exeptions below)
;                    - Returns a 1D array with the following
;                       - [0] = Username
;                       - [1] = Password
;                    - Exeptions:
;                       - When bBlank is True and
;                       The timeout has been reached
;                          - @extended = 1
;                          - @error = 0
;                 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(1, 1, 0)
    ElseIf $case = 2 Then;Timed Out
        GUIDelete($gui)
        Return SetError(1, 2, 0)
    ElseIf $case = 1 Then;Ok Pressed
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return SetError(0, 0, $retarr)
    ElseIf $case = 3 Then;Username Fields Not Blank, Timeout reached
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return SetError(0, 1, $retarr)
    EndIf
EndFunc ;==>_LoginBox

any help would be appreciated, thank you in advance

Education: Francis Tuttle Technology Center adult full-time studentCourse of study: Network TechnologyCurrent Course: Microsoft Windows Server 2003, Enterprise EditionCompleted Courses: CompTIA A+ Hardware and Software, Windows XP Professional, Microsoft Office 2003, Desktop Support and Troubleshooting, and CompTIA Network+Remaining Courses: Linux Administration, Copper Cabling, Microsoft Windows Server 2003, Enterprise EditionAchievements: @17 years old, scored 98th percentile U.S. in Algebra 2 and Advanced Chemistry. [i.e. Ranked top 2% in the nation of High School students]

Link to comment
Share on other sites

In your code example, on line 21 you call the _LoginBox() function, but you don't pass it any parameters. Your function has two "required" parameters that it is expecting at a minimum when the function is called - "Title" and "Prompt"

In this case, it would be appropriate to use something along the lines of:

_LoginBox("Login","Enter your username and password below:")

You'll also want to add in handling for if the user clicks "Cancel" and such.

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...