Jump to content

_LoginBox


BrettF
 Share

Recommended Posts

_LoginBox UDF

:) A simple script that shows a customizable login box, with User, Password, Prompt etc ;)

Current Version: 4

Last Updated: 6 Febuary 2009

Download Link

(Direct)

This script is fairly simple. It shows a customizable "login box", housing a username and password field, along with user-defined options. It can easily be added to you script. The download includes the function along with the example.

PLEASE NOTE: THIS FUNCTION IS NOT DESIGNED TO DO ANY OF THE FOLLOWING; AUTOMATICALLY LOG YOU INTO A WEBPAGE/PROGRAM/WINDOWS/ETC, STORE YOUR PASSWORDS (THIS FUNCTION RECEIVES THE USERNAME AND PASSWORD, THEN PASSES IT TO THE SCRIPT USING THE RETURN VALUE). IT IS NOT DESIGNED TO DO ANY OF THESE THINGS, SO THEY WILL NOT BE IMPLEMENTED.

Comment Appreciated. Enjoy :P

Thanks To:

JerryD

GEOSoft

Changelog:

UPDATED 3! Thanks GeoSoft, a whole ton of updates to the function. (August 20 2008)

UPDATED 2! I think I have a way to stop the errors from popping up. Just a nuther parameter... (October 11 2007)

UPDATED! Thanks to JerryD's ideas, this is so much better. The timeout does get annoying though... Comments on how that part could be better appreciated. (October 11 2007)

INITIAL VERSION! October 10 2007

Edited by BrettF
Link to comment
Share on other sites

  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

It Is? Where? I don't see one. Never have... No offence taken... And tell me. Does KODA do anything else with the GUI? Create the functions... Set the errors... I think not.

Link to comment
Share on other sites

It Is? Where? I don't see one. Never have... No offence taken... And tell me. Does KODA do anything else with the GUI? Create the functions... Set the errors... I think not.

Bert - don't worry about that (and I don't know what ashley means by the gui is already made for you anyway). It's a nice enough function that I'm planning on using it soon, although with a few modifications...

  • Your default values in the function declaration for $left and $top set the values to 0 and put the login box in the top left corner of the screen, but the default -1 centers it on the screen. It doesn't really matter which it is, it's just inconsistent (using no parameter should behave the same as using the -1 parameter).
  • Once the password is typed in, hitting [Enter] doesn't do anything - you have to hit [OK]. Adding the line GUICtrlSetState($okbtn, $GUI_DEFBUTTON) makes the OK button the default action when [Enter] is hit.
  • I would use seterror differently. Right now the function returns a value (array) if it works, but returns ??? if Cancel or Exit is returned. I would return 0 in those lines. Your SetError(0, 1) is setting @error to 0, and @extended to 1 (or 2 if timed out). It would be more effective if you used SetError(1, 1,0) for returning Cancel/Exit and SetError(1, 2,0) for the function timing out. That way, you can use either If NOT _LoginBox() or If @error.
On my enhancement list:
  • rework the GUI to use all relative positioning so that buttons, labels, etc. are more dynamic relative to the size of the size of the form
  • Restrict the minimum size allowed for all dimenstions (along with item above)
  • allow setting the active control to either the username field or the password field
  • change the default timeout to 0 and change the line to Case TimerDiff($time) > $timeout And $timeout (I think it would be a tad quicker)
And please keep in mind, I wouldn't even waste my time posting if the function wasn't worth the trouble - it's fundamentally a very nice funtion. And I will NOT be offended if you couldn't care less about what I think of it either. My only intent is to compliment your work.
Link to comment
Share on other sites

Bert - don't worry about that (and I don't know what ashley means by the gui is already made for you anyway). It's a nice enough function that I'm planning on using it soon, although with a few modifications...

  • Your default values in the function declaration for $left and $top set the values to 0 and put the login box in the top left corner of the screen, but the default -1 centers it on the screen. It doesn't really matter which it is, it's just inconsistent (using no parameter should behave the same as using the -1 parameter).
  • Once the password is typed in, hitting [Enter] doesn't do anything - you have to hit [OK]. Adding the line GUICtrlSetState($okbtn, $GUI_DEFBUTTON) makes the OK button the default action when [Enter] is hit.
  • I would use seterror differently. Right now the function returns a value (array) if it works, but returns ??? if Cancel or Exit is returned. I would return 0 in those lines. Your SetError(0, 1) is setting @error to 0, and @extended to 1 (or 2 if timed out). It would be more effective if you used SetError(1, 1,0) for returning Cancel/Exit and SetError(1, 2,0) for the function timing out. That way, you can use either If NOT _LoginBox() or If @error.
On my enhancement list:
  • rework the GUI to use all relative positioning so that buttons, labels, etc. are more dynamic relative to the size of the size of the form
  • Restrict the minimum size allowed for all dimenstions (along with item above)
  • allow setting the active control to either the username field or the password field
  • change the default timeout to 0 and change the line to Case TimerDiff($time) > $timeout And $timeout (I think it would be a tad quicker)
And please keep in mind, I wouldn't even waste my time posting if the function wasn't worth the trouble - it's fundamentally a very nice funtion. And I will NOT be offended if you couldn't care less about what I think of it either. My only intent is to compliment your work.
Thankyou Jerry :) That's the type of feedback I like. :P I will take that all on board, and when I get out of bed, I will fix it up when I am at school. Thankyou ;)
Link to comment
Share on other sites

I like the layout, add those great suggestions by JerryD and the UDF will be a lot better. :)

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

  • 9 months later...

Good work Brett.

Tidy is reporting errors but I don't see any in the script so I suspect it's just Tidy.

Edit. Why are you allowing defaults for the username and password? Isn't the purpose of a login dialog to force the user to enter those values? Personally I would remove those two parameters, but that's just me.

Edit 2. I solved the Tidy Errors (code available) but there is one error that I just spotted.

$Label1 = GUICtrlCreateLabel("Password:", 4, 72, 62, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Username:", 4, 44, 64, 17)
Both inputs have the same variable name. But no matter, because you don't need to name them anyway since they are not referenced again. Edited by GEOSoft

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

great work man you should add in call authentication too.

What do you mean by "call authentication"? Example?

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

  • 3 weeks later...

You have this setup all whack...

#include <GUIConstants.au3>
#include <EditConstants.au3>
$ret = _LoginBox("Enter Credentials", "Please enter you username and password", "username", "password", -1, -1, -1, -1, -1, 0)
If Not @error Then
    MsgBox(0, "Credentails Returned", "Username: " & $ret[0] & @CRLF & "Password: " & $ret[1])
EndIf

That doesn't work. It doesn't give me the info when i press ok, but this does:

#include <GUIConstants.au3>
#include <EditConstants.au3>
$ret = _LoginBox("Enter Credentials", "Please enter you username and password", "username", "password", -1, -1, -1, -1, -1, 0)
If @error Then
    MsgBox(0, "Credentails Returned", "Username: " & $ret[0] & @CRLF & "Password: " & $ret[1])
EndIf

EDIT: And -1 doesn't work for the timeout, you have to have 0...

EDIT: You also need EditConstants included or else it wil error out with $ES_Password.

Edited by Alienware
Link to comment
Share on other sites

Very nice Brett. What happened to the default username/password spot? Also, maybe you should have at the very end a $hHwnd parameter, like the messagebox does.

having a default password makes no sense at all. The idea is to force someone to enter the information. If you used default username and password then all that was required was to click the OK button, which anyone could do. That bypasses the security that you wanted to begin with.

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

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