Jump to content

_LoginBox


BrettF
 Share

Recommended Posts

Link to comment
Share on other sites

  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

More designed for the user to use the user name and password how they want and need...

I'll add the HWND parameter soon ;)

Thank you for sharing this code, the parameters are intresting. I'm doing something like that but i have also added an option to accept a PIN code (4 chars 1->9) without user. this is for less secure applications where people need a fast access to the application (ie: hospitals).

Link to comment
Share on other sites

  • 2 months later...

Thank you for sharing this code, the parameters are intresting. I'm doing something like that but i have also added an option to accept a PIN code (4 chars 1->9) without user. this is for less secure applications where people need a fast access to the application (ie: hospitals).

Sorry it took so long to reply, but thanks! Any chance you could post your modifications?? :(

Also, the main reason for the resurection, I have updated download link. Been doing a lot of work on my site... :mellow:

Link to comment
Share on other sites

  • 2 months later...

Maybe I am naive but this is a HUGE script for a simple GUI. I am complaining because when I tried to download it and look at it, the server errored out and what I got was a text of the file. The "CODE" was one continous line when pasted into Scite, and I had to read it and break it up where I thought it was supposed to be broke up at hehe.

I got halfway done and said screw it, I'll try to redownload it at home, where my server isn't blocking files of a large size lol.

May I ask what exactly is the purpose of all the code? I understand you want a timeout function, and error handling making sure there is no "" entry, but couldn't you do that in a function when the OK is pressed, and make it MUCH smaller file?

I am a novice coder, so excuse my ignorance if this is a dumb question.

Link to comment
Share on other sites

Read the 2 previous posts before yours. There is a direct link. As mentioned before it is more than a general GUI, it has other features and proper error checking (I'm pretty sure its all correct :rolleyes)... I also prefer that its all in one function... :)

But if you don't like it, you don't have to use it :lmao:

Cheers,

Brett

Link to comment
Share on other sites

  • 2 weeks later...

Looks cool. I'm not too concerned about restricting program use on our intranet, but I do have a few checks in programs that simply look at @ComputerName and limit certain commands accordingly. That is, of course, very weak. I may have to stick this in instead. I do see irregularities in the code that you'll likely cleanup in later versions? Well, in the meantime, I addressed those issues and yanked out some of the fluff. I may use a _LoginBox based on yours, something like:

Global $ret[2]
While Not $ret[0] = "end"
    $ret = _GUICreateLogin(-1, "Enter username and password", False, -1, -1, 5, 30)
    If @error Then
        MsgBox(0, "Error", "Error: " & $ret[0] & " - " & $ret[1], 5)
    Else
        MsgBox(0, "Login", "Username: " & $ret[0] & "   " & "Password:  " & $ret[1])
    EndIf
WEnd
Exit

;===============================================================================
; Function Name:   _GUICreateLogin()
; Description:   Create a basic login box with Username, Password, and a prompt.
; Syntax:
; Parameter(s): $hTitle - The title of the Form [optional]
;                 $hPrompt - The text prompt for the user [optional] (maximum of 2 lines)
;                 $bBlank - The password can be blank. [optional]
;                           Default = False (Blanks are not allowed)
;                 $hLeft - X position [optional] - default = centered
;                 $hTop - Y position [optional] - default = centered
;                 $hRetries - Maximum allowable login attempts [optional - default = 0 (unlimited attempts)
;                 $Timeout - The timeout of the form in seconds [optional - default = 0 (no timeout)
; Requirement(s):  None
; Return Value(s): Success - Returns an array of 2 elements where
;                                       [0] = UserName
;                                       [1] = Password
;                 Failure - Sets @Error to:
;                                       1 = Cancel/Exit Button Pressed
;                                       2 = Timed out
;                                       3 = Maximum attempts exceeded
;                              Returns an array of 2 elements where
;                                       [0] = Error code
;                                       [1] = Error Description
; Author(s):   Brett Francis (exodus.is.me@hotmail.com)
; Modification(s): GeoSoft, Spiff59
; Example(s):
;===============================================================================

Func _GUICreateLogin($hTitle = -1, $hPrompt = "", $bBlank = False, $hLeft = -1, $hTop = -1, $hRetries = 0, $timeout = 0)
    If $hTitle = -1 Then $hTitle = "Login"
    If StringRegExp($bBlank, "(?i)\s|default|-1") Then $bBlank = False
    If StringRegExp($hLeft, "(?i)\s|default|-1") Then $hLeft = -1
    If StringRegExp($hTop, "(?i)\s|default|-1") Then $hTop = -1
    If StringRegExp($hRetries, "(?i)\s|default|-1") Then $hRetries = 3
    $gui = GUICreate($hTitle, 240, 145, $hLeft, $hTop)
    GUISetFont(8, 600, 0, "MS Sans Serif")
    GUICtrlCreateLabel($hPrompt, 10, 10, 220, 30, 1)
    GUICtrlCreateLabel("Username:", 10, 35, 65, 16)
    Local $username = GUICtrlCreateInput('', 80, 33, 150, 18)
    GUICtrlCreateLabel("Password:", 10, 65, 65, 16)
    Local $password = GUICtrlCreateInput('', 80, 63, 150, 18)
    Local $Btn_OK = GUICtrlCreateButton("OK", 30, 95, 80, 25, 1)
    Local $Btn_Cancel = GUICtrlCreateButton("Cancel", 130, 95, 80, 25)
    $StatusMsg = GUICtrlCreateLabel("", 10, 125, 220, 16, 1)
    GuiCtrlSetColor(-1, 0xFF0000); red
    GUISetState()

;---------------------------------------------------------------------------------------------------
    Local $retarr[2] = ["", ""], $Time, $eMsg, $Status, $Retries = 0
    If $timeout Then
        $timeout *= 1000
        $Time = TimerInit()
    EndIf
    While 1
        If $timeout And (TimerDiff($Time) >= $timeout) Then
            $Status = 2; timeout
            $eMsg = "Login timed out"
            ExitLoop
        EndIf
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $Btn_OK
                Local $sUser = GUICtrlRead($username)
                Local $sPass = GUICtrlRead($password)
                If $sUser = "" Then
                    GUICtrlSetData($StatusMsg, "Username cannot be blank")
                    GUICtrlSetState($username, 256)
                ElseIf $bBlank + ($sPass<>"") Then
                    $Status = 0; good
                    ExitLoop
                Else
                    GUICtrlSetData($StatusMsg, "Password cannot be blank")
                    GUICtrlSetState($password, 256)
                EndIf
                $Retries += 1
                If $Retries = $hRetries Then
                    $Status = 3; retries exceeded
                    $eMsg = "Maximum attempts"
                    ExitLoop
                EndIf
            Case $Btn_Cancel, -3
                $Status = 1; cancel
                $eMsg = "Login cancelled"
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($gui)
    If $Status Then
        $retarr[0] = $Status
        $retarr[1] = $eMsg
        SetError($Status)
    Else
        $retarr[0] = $sUser
        $retarr[1] = $sPass
    EndIf
    Return $retarr
EndFunc ;==>_GUICreateLogin
Edited by Spiff59
Link to comment
Share on other sites

If I were you I would be careful with this line in a function where the variable is a parameter with no value in the function call.

If Not $hTitle Then $hTitle = "Login"

If you want that then it willl be safer to use

Func _GUICreateLogin($hTitle = "", $hPrompt = "", ..........

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

If I were you I would be careful with this line in a function where the variable is a parameter with no value in the function call.

If Not $hTitle Then $hTitle = "Login"

If you want that then it willl be safer to use

Func _GUICreateLogin($hTitle = "", $hPrompt = "", ..........
I'm not sure if that was addressed to me, as that situation with $hTitle appears to have been in the function since day one. It wasn't a line I paid much attention to. I'm just curious, though, what is the caveat or loophole that makes the way it is presently coded undesirable? I'm only aware of the case that if an unquoted 0 were passed to the function, that it would get replaced with "Login". The statement "If $hTitle == "" Then $hTitle = "Login" would probably address that concern. Are there other pitfalls to not assigning a default value to an optional parameter in a function statement?

Edit: I drank too much coffee this morning!

Edited by Spiff59
Link to comment
Share on other sites

I'm not sure if that was addressed to me, as that situation with $hTitle appears to have been in the function since day one. It wasn't a line I paid much attention to. I'm just curious, though, what is the caveat or loophole that makes the way it is presently coded undesirable? I'm only aware of the case that if an unquoted 0 were passed to the function, that it would get replaced with "Login". The statement "If $hTitle == "" Then $hTitle = "Login" would probably address that concern. Are there other pitfalls to not assigning a default value to an optional parameter in a function statement?

Edit: I drank too much coffee this morning!

Try running it without specifying the parameter and see what you get. It will work only if you use a blank ("") for that parameter.

To make that line work properly the function really should be

Func _GUICreateLogin($hTitle="",.........................)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

And that it has. You reckon the main UDF needs to be updated to reflect that George?

I would Brett. I seem to recall that may have been one of the changes I sent you early on. You can either remove that line or just change the parameter.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • 4 months later...

I would say something as I set the password / login to open the program?

or better know as I would say that this person loginBox to enter the login and password for my forum / site to access the program with your account?

How would this script? I do not have a clue, would I say?

-------------------------------------------------------------------------------------------------------------------------------------------- [center][/center][center]Autoit Support Forum in Portuguese | AutoitBrasil.com[/center] [sub]My Script :[/sub]Simples Login for Program

Link to comment
Share on other sites

Please see the example. You will notice this function is only designed to recieve user credentials. Not log in to a site etc. That part has to be done by you.

For your first question, you will need to set up your own way of controlling credentials, for reasons stated before. Please note that the function returns an array, so you should double check them against your required credentials in an If...Then...Else...EndIf statement, then you should be okay. Just give it a go first :D

As for your part, I have no idea what your asking.

Cheers,

Brett

Link to comment
Share on other sites

My question is if this script, the way it is now, would make for a script, the login is used to the program, and the person must have an account on the site / forum, and to use the program it must enter login / password to open the program

already asked for multiple users on this issue, many say, very simple and easy to make a Login Script to program, but has some who speak that way and hard

Some say that should be used _IE functions, but I never used them, I think it really is true I will try at most, because I have great difficulty creating scripts, but not, my biggest difficulty is to read the Autoit Help " (F1), because my English is very bad, I understand a lot, but also has many things I do not understand

Therefore I think the Autoitv4 (maybe future) might have different language

As:

Portuguese, Spanish (Updated), France and other

-------------------------------------------------------------------------------------------------------------------------------------------- [center][/center][center]Autoit Support Forum in Portuguese | AutoitBrasil.com[/center] [sub]My Script :[/sub]Simples Login for Program

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...