Login

Get help with using AutoHotkey and its commands and hotkeys
gucci
Posts: 23
Joined: 12 Mar 2017, 18:15

Login

14 Mar 2017, 21:20

Hey, so I need your guys help coding this. I have a program, and I just need to make a basic auth, a basic login before they enter the real program. Butttt, I need to finish this program quickly, and I really have no idea how to do this. Anyways, I have the gui for the login; don't worry about that. I just need you guys someone to make it work. What I need you to code is just make the username username and make the password password, but this is the part I don't get. I have the script for my program, and I want for before the program acctualy opens I want this login gui to come up, and if your login is right, you get into the program. But I need you guys to show me how I can add multiple usernames and passwords, like I can register other people for the program as well. So I need you guys to help me code what I said, but I need it to be able to be attached to my actual program script, so it opens before the actual program, and if you get it wrong nothing happens. Thanks!!!

GUI Code:

Code: Select all

Gui, Add, Text, x12 y10 w80 h20 , Username:
Gui, Add, Edit, x72 y10 w170 h20 , 
Gui, Add, Text, x12 y50 w60 h20 , Password:
Gui, Add, Edit, x72 y50 w170 h20 , 
Gui, Add, Button, x82 y80 w90 h30 , Login
Gui, Show, x137 y95 h123 w256, 
A_AhkUser
Posts: 1076
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: Login

14 Mar 2017, 21:44

create a new ini (https://www.autohotkey.com/docs/commands/IniRead.htm) file in your own script directory, call it login.ini:

for exemple it could look like:

Code: Select all

[users]
gucci=9999
otherUser=7659
concerning the ahk script:

Code: Select all

Gui, Add, Text, x12 y10 w80 h20 , Username:
Gui, Add, Edit, vUserName x72 y10 w170 h20 , 
Gui, Add, Text, x12 y50 w60 h20 , Password:
Gui, Add, Edit, vPassword x72 y50 w170 h20 +Password , 
Gui, Add, Button, x82 y80 w90 h30 gLogin, Login
Gui, Show, x137 y95 h123 w256, 
return

Login:
Gui, Submit
IniRead, realPassword, % A_ScriptDir . "/login.ini", users, % UserName
if (password == realPassword)
MsgBox, да
else
MsgBox, 16,, нет
ExitApp
gucci
Posts: 23
Joined: 12 Mar 2017, 18:15

Re: Login

14 Mar 2017, 22:11

A_AhkUser wrote:create a new ini (https://www.autohotkey.com/docs/commands/IniRead.htm) file in your own script directory, call it login.ini:

for exemple it could look like:

Code: Select all

[users]
gucci=9999
otherUser=7659
concerning the ahk script:

Code: Select all

Gui, Add, Text, x12 y10 w80 h20 , Username:
Gui, Add, Edit, vUserName x72 y10 w170 h20 , 
Gui, Add, Text, x12 y50 w60 h20 , Password:
Gui, Add, Edit, vPassword x72 y50 w170 h20 +Password , 
Gui, Add, Button, x82 y80 w90 h30 gLogin, Login
Gui, Show, x137 y95 h123 w256, 
return

Login:
Gui, Submit
IniRead, realPassword, % A_ScriptDir . "/login.ini", users, % UserName
if (password == realPassword)
MsgBox, да
else
MsgBox, 16,, нет
ExitApp
Is there any way to have no login.ini, im sure there is...
A_AhkUser
Posts: 1076
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: Login

14 Mar 2017, 22:32

Code: Select all

users := {"gucci":9999, "otherUser":7659}

Gui, Add, Text, x12 y10 w80 h20 , Username:
Gui, Add, Edit, vUserName x72 y10 w170 h20 , 
Gui, Add, Text, x12 y50 w60 h20 , Password:
Gui, Add, Edit, vPassword x72 y50 w170 h20 +Password , 
Gui, Add, Button, x82 y80 w90 h30 gLogin, Login
Gui, Show, x137 y95 h123 w256, 
return

Login:
Gui, Submit
if (password == users[Username])
MsgBox, C'est le bon mot de passe!
else
MsgBox, 16,, C'est le mauvais mot de passe.
ExitApp
?
gucci
Posts: 23
Joined: 12 Mar 2017, 18:15

Re: Login

14 Mar 2017, 22:55

A_AhkUser wrote:

Code: Select all

users := {"gucci":9999, "otherUser":7659}

Gui, Add, Text, x12 y10 w80 h20 , Username:
Gui, Add, Edit, vUserName x72 y10 w170 h20 , 
Gui, Add, Text, x12 y50 w60 h20 , Password:
Gui, Add, Edit, vPassword x72 y50 w170 h20 +Password , 
Gui, Add, Button, x82 y80 w90 h30 gLogin, Login
Gui, Show, x137 y95 h123 w256, 
return

Login:
Gui, Submit
if (password == users[Username])
MsgBox, C'est le bon mot de passe!
else
MsgBox, 16,, C'est le mauvais mot de passe.
ExitApp
?
Like is there anyway to hold all the accounts inside the program?
gucci
Posts: 23
Joined: 12 Mar 2017, 18:15

Re: Login

15 Mar 2017, 17:41

A_AhkUser wrote:

Code: Select all

users := {"gucci":9999, "otherUser":7659}

Gui, Add, Text, x12 y10 w80 h20 , Username:
Gui, Add, Edit, vUserName x72 y10 w170 h20 , 
Gui, Add, Text, x12 y50 w60 h20 , Password:
Gui, Add, Edit, vPassword x72 y50 w170 h20 +Password , 
Gui, Add, Button, x82 y80 w90 h30 gLogin, Login
Gui, Show, x137 y95 h123 w256, 
return

Login:
Gui, Submit
if (password == users[Username])
MsgBox, C'est le bon mot de passe!
else
MsgBox, 16,, C'est le mauvais mot de passe.
ExitApp
?
Thanks this works! But how would I attach a different gui to it? So lets say the username and password is correct, I want it to go to my offical program (A gui) How would I do this?
99muppets
Posts: 83
Joined: 08 Mar 2017, 19:45

Re: Login

15 Mar 2017, 17:53

Try this

Code: Select all

Gui, Add, Text, x12 y10 w80 h20 , Username:
Gui, Add, Edit, vUserName x72 y10 w170 h20 , 
Gui, Add, Text, x12 y50 w60 h20 , Password:
Gui, Add, Edit, vPassword x72 y50 w170 h20 +Password , 
Gui, Add, Button, x82 y80 w90 h30 gLogin, Login
Gui, Show, x137 y95 h123 w256, 
return

Login:
Gui, Submit
if (password == users[Username])
MsgBox, 16,, C'est le mauvais mot de passe.
else
Gui Destroy ;this gets rid of the first GUI
;Your other GUI code here
99muppets
Posts: 83
Joined: 08 Mar 2017, 19:45

Re: Login

15 Mar 2017, 18:43

Sorry, the last script i gave you was faulty, try this one

Code: Select all

;here you can edit the username/passwords
username=u
password=v

InputBox, user, Please Enter User Name
InputBox,pass, Please Enter Password
If (user!=%username%||pass!=%password%) {
;your gui here
}
Else
MsgBox, Wrong
Return
gucci
Posts: 23
Joined: 12 Mar 2017, 18:15

Re: Login

15 Mar 2017, 21:51

99muppets wrote:Sorry, the last script i gave you was faulty, try this one

Code: Select all

;here you can edit the username/passwords
username=u
password=v

InputBox, user, Please Enter User Name
InputBox,pass, Please Enter Password
If (user!=%username%||pass!=%password%) {
;your gui here
}
Else
MsgBox, Wrong
Return
Lol, it's fine I already have it xd. But there is something you can help me with. This is the code im using for the login

Code: Select all

users := {"gucci":9999, "otherUser":7659}

Gui, Add, Text, x12 y10 w80 h20 , Username:
Gui, Add, Edit, vUserName x72 y10 w170 h20 , 
Gui, Add, Text, x12 y50 w60 h20 , Password:
Gui, Add, Edit, vPassword x72 y50 w170 h20 +Password , 
Gui, Add, Button, x82 y80 w90 h30 gLogin, Login
Gui, Show, x137 y95 h123 w256, 
return

Login:
Gui, Submit
if (password == users[Username])
Gui, Show
else 
MsgBox, 16,, Your username or password is not correct
ExitApp

And bassicaly I want to attach it to a program, before the real program starts I want this to come up. Lets just say this is the script for the real program

Code: Select all

Gui, Show, x500 y500 w300 h300
Gui, Add, Text, x100 y100 w50 h50, Hey
return
GuiClose:
ExitApp
Please help!!! Thanks!!! !!!
99muppets
Posts: 83
Joined: 08 Mar 2017, 19:45

Re: Login

15 Mar 2017, 23:18

I'll get back to you in a bit, using my phone rn
99muppets
Posts: 83
Joined: 08 Mar 2017, 19:45

Re: Login

15 Mar 2017, 23:28

It's a weirdly complicated piece
If code. Honestly I don't quite understand what everything in you code
Means and I'm not sure
If it even works but put this under
if (password == users[username])

Gui, Show, x500 y500 w300 h300
Gui, Add, Text, x100 y100 w50 h50, Hey
return
99muppets
Posts: 83
Joined: 08 Mar 2017, 19:45

Re: Login

15 Mar 2017, 23:31

Have a play around with your original code, because
I'm not sure that the username matters

Honestly I would
Really recommend the second GUI that I sent you, its significantly easier
To edit, use
And I'm 100% that it
Works
gucci
Posts: 23
Joined: 12 Mar 2017, 18:15

Re: Login

16 Mar 2017, 10:01

99muppets wrote:Have a play around with your original code, because
I'm not sure that the username matters

Honestly I would
Really recommend the second GUI that I sent you, its significantly easier
To edit, use
And I'm 100% that it
Works
Well... Dosen't really work. I paste my actual program gui where you told me too, and only when I enter the username it launches if the username is right it launches it, it dosen't ask for password, it launches the gui, but I don't see it... So...
A_AhkUser
Posts: 1076
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: Login

16 Mar 2017, 11:46

hi guys!

99muppet you said:
It's a weirdly complicated piece If code
Not sure about that: sure you code with two inputbox:

Code: Select all

InputBox, user, Please Enter User Name
InputBox,pass, Please Enter Password
does the job but do you even know the meaning of

Code: Select all

Gui, Submit
?
Documentation (https://www.autohotkey.com/docs/commands/Gui.htm#Submit) says:
Saves the contents of each control to its associated variable (if any) and hides the window unless the NoHide option is present.
In the piece of code:

Code: Select all

Gui, Add, Edit, vUserName x72 y10 w170 h20 ,
"v" help us to set the associated output variable of the control (https://www.autohotkey.com/docs/commands/Gui.htm#var)
so when

Code: Select all

Gui, Submit
is called in UserName there will have the content of the control (edit control's text for instance). Btw did you even see a login using 2 gui, 2 inputbox like
yours? ;)

so

Code: Select all

users[Username]
means

Code: Select all

users[whatTheUserLetInTheFirstControlEditOfTheGUI]
and as you can see

Code: Select all

users := {"gucci":9999, "otherUser":7659}
if its "gucci" so 9999 and if it's "otheruser" 7659. Also note taht the advantage here is that we only create one variable (users) and we can retieves users as property of users

Code: Select all

users["gucci"]
(btw the way if the name of your user content space it does works in this case - for instance:

Code: Select all

MsgBox % user["John Doe"]
works
whereas

Code: Select all

 Joe Doe = 4
will display Error MsgBox

so 99muppets I really recommend using the first GUI that I sent - although you make good suggestions
and you've right we you're saying:

Code: Select all

100% that it Works
Concerning Gucci it's one of two things either you ask others helping you doing your script or your said something like "I need you to code" both are OK no problems ; in you first post of this thread there two ones so its ambiguous and I don't no if you need help (and if this case doing the job instead of you it is not helping you and if you actually need help post some piece of code please)
gucci
Posts: 23
Joined: 12 Mar 2017, 18:15

Re: Login

16 Mar 2017, 12:30

A_AhkUser wrote:hi guys!

99muppet you said:
It's a weirdly complicated piece If code
Not sure about that: sure you code with two inputbox:

Code: Select all

InputBox, user, Please Enter User Name
InputBox,pass, Please Enter Password
does the job but do you even know the meaning of

Code: Select all

Gui, Submit
?
Documentation (https://www.autohotkey.com/docs/commands/Gui.htm#Submit) says:
Saves the contents of each control to its associated variable (if any) and hides the window unless the NoHide option is present.
In the piece of code:

Code: Select all

Gui, Add, Edit, vUserName x72 y10 w170 h20 ,
"v" help us to set the associated output variable of the control (https://www.autohotkey.com/docs/commands/Gui.htm#var)
so when

Code: Select all

Gui, Submit
is called in UserName there will have the content of the control (edit control's text for instance). Btw did you even see a login using 2 gui, 2 inputbox like
yours? ;)

so

Code: Select all

users[Username]
means

Code: Select all

users[whatTheUserLetInTheFirstControlEditOfTheGUI]
and as you can see

Code: Select all

users := {"gucci":9999, "otherUser":7659}
if its "gucci" so 9999 and if it's "otheruser" 7659. Also note taht the advantage here is that we only create one variable (users) and we can retieves users as property of users

Code: Select all

users["gucci"]
(btw the way if the name of your user content space it does works in this case - for instance:

Code: Select all

MsgBox % user["John Doe"]
works
whereas

Code: Select all

 Joe Doe = 4
will display Error MsgBox

so 99muppets I really recommend using the first GUI that I sent - although you make good suggestions
and you've right we you're saying:

Code: Select all

100% that it Works
Concerning Gucci it's one of two things either you ask others helping you doing your script or your said something like "I need you to code" both are OK no problems ; in you first post of this thread there two ones so its ambiguous and I don't no if you need help (and if this case doing the job instead of you it is not helping you and if you actually need help post some piece of code please)
Sorry about that :(
So the script you coded me, works amazingly, but I just can't figure out where to put my actual program gui. I assume you put it here;

Code: Select all

Login:
Gui, Submit
if (password == users[Username])
(the gui/other script)
But thats not the case, because it pops up with a box saying "ELSE with no matching IF" (line 21 which sais else)
For example lets say this is my actual gui, with the login;

Code: Select all

users := {"gucci":9999, "otherUser":7659}

Gui, Add, Text, x12 y10 w80 h20 , Username:
Gui, Add, Edit, vUserName x72 y10 w170 h20 , 
Gui, Add, Text, x12 y50 w60 h20 , Password:
Gui, Add, Edit, vPassword x72 y50 w170 h20 +Password , 
Gui, Add, Button, x82 y80 w90 h30 gLogin, Login
Gui, Show, x137 y95 h123 w256, 
return

Login:
Gui, Submit
if (password == users[Username])
Gui, Show, x500 y500 w300 h300
Gui, Add, Text, x100 y100 w100 h100 ,Hey
return
GuiClose:
ExitApp
else 
MsgBox, 16,, Your username or password is not correct
ExitApp

It's just a test gui :P but then pops up with the ELSE with no matching IF. Please help me with this thanks!
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
GitHub: 4GForce

Re: Login

16 Mar 2017, 12:45

gucci wrote:And bassicaly I want to attach it to a program, before the real program starts I want this to come up. Lets just say this is the script for the real program
Follow this template ...

Code: Select all

#singleinstance force

gosub ShowLogin

Return

ShowLogin:
	; build and show your login gui here
Return

Login:	; this is called from the login gui
	Gui, Submit
	if (password == users[Username]) {
		goto MainGui		; user is logged in so we go to the main gui subroutine
	}
	else {
		MsgBox, 16,, Your username or password is not correct
		ExitApp
	}
Return

MainGui:
	; build and show your main gui here
Return
Hope this helps !
A_AhkUser
Posts: 1076
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: Login

16 Mar 2017, 14:10

Sorry about that :(
No sorry it's me I made a real fuss for nothing...


4GForce make a great template I assume you will manage to make your own login
also to perfect this one you could add an if statement like this one

if not (the username exist)
{
MsgBox, your username does'nt exist.
}
else if (the password is incorrect)
{
MsgBox, your username is incorrect
}
else (login succeded)
{
; ...
}

we already can check the second and the third conditions.

now, all object like this one:

Code: Select all

users := {"gucci":9999, "otherUser":7659}
have a method HasKey (https://autohotkey.com/docs/objects/Object.htm#HasKey) to determine whether or not it content a specified key like "gucci" or not so the first:

Code: Select all

if (the username is registered)
{
MsgBox, your username does'nt exist.
}
can be easely implemented
also note that

Code: Select all

Gui, Submit
can accept a parameter

Code: Select all

Gui, Submit, NoHide
which say ahk not hide the gui -- so if the user fails it can make other attempts the gui will remain here to allows it

try it out and let us see the final script it will serve as template for login for others :)
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
GitHub: 4GForce

Re: Login

16 Mar 2017, 15:47

A_AhkUser wrote: if not (the username exist)
{
MsgBox, your username does'nt exist.
}
else if (the password is incorrect)
{
MsgBox, your username is incorrect
}
else (login succeded)
{
; ...
}
Logins don't usually specify if the username or password is incorrect, just incorrect credentials.
Reason being that it would tip potential hacker on what field to brute force.
Edit: After checking, the login to this forum does tell you Wrong username / Wrong password ( but then again the usernames are public anyway )
That being said, this login method isn't safe anyway, even after compiling your code, the credentials will still appear in the .exe
You could use some encryption and store those in a binary file but then again this can be bypassed.
Even if you'd use a secure database, someone could bypass the login part of the code and get the main code to run.
Nothing is full-proof, question is: How much time and resources are you willing to invest in security ?
gucci
Posts: 23
Joined: 12 Mar 2017, 18:15

Re: Login

16 Mar 2017, 15:57

4GForce wrote:
gucci wrote:And bassicaly I want to attach it to a program, before the real program starts I want this to come up. Lets just say this is the script for the real program
Follow this template ...

Code: Select all

#singleinstance force

gosub ShowLogin

Return

ShowLogin:
	; build and show your login gui here
Return

Login:	; this is called from the login gui
	Gui, Submit
	if (password == users[Username]) {
		goto MainGui		; user is logged in so we go to the main gui subroutine
	}
	else {
		MsgBox, 16,, Your username or password is not correct
		ExitApp
	}
Return

MainGui:
	; build and show your main gui here
Return
Hope this helps !
Yes, it does! Just one thing you have to add, if anyone wants to copy this script, go ahead!
But if you do not add the thing im about to tell you, what it will do is fuse the 2 gui's together after you login, soooo...
This is what you need to add

Code: Select all

#singleinstance force

gosub ShowLogin

Return

ShowLogin:
	; build and show your login gui here
Return

Login:	; this is called from the login gui
	Gui, Submit
	if (password == users[Username]) {
		[b][u][i][color=#FF0000]Gui Destroy[/color][/i][/u][/b]
		goto MainGui		; user is logged in so we go to the main gui subroutine
	}
	else {
		MsgBox, 16,, Your username or password is not correct
		ExitApp
	}
Return
The Gui Destroy makes it if you get the right password and username it destroys the login gui, and goes to the next gui!
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
GitHub: 4GForce

Re: Login

16 Mar 2017, 16:03

gucci wrote:The Gui Destroy makes it if you get the right password and username it destroys the login gui, and goes to the next gui!
That works ...
Gui New would do the same thing
Naming the guis is also always a good practice to avoid confusion
Gui LoginGui:New
Gui MainGui:New
https://autohotkey.com/docs/commands/Gui.htm#MultiWin

Return to “Ask For Help”

Who is online

Users browsing this forum: flyingDman, Google [Bot], joshuajclark, Odlanir, Sashkon, tom0925 and 106 guests