Spoiler
Code: Select all
; Create a dictionary to store registered users
users := {}
; Show the login GUI
ShowLogin()
; Function to show the login GUI
ShowLogin() {
Gui, +AlwaysOnTop
Gui, Add, Text, vUsername x20 y20, Username:
Gui, Add, Edit, vUsername x100 y20 w150,
Gui, Add, Text, vPassword x20 y50, Password:
Gui, Add, Edit, vPassword x100 y50 w150 password,
Gui, Add, Button, gLogin x20 y80, Login
Gui, Add, Button, gRegister x150 y80, Register
Gui, Show
}
; Function to handle the login button click
Login:
; Check if the entered username and password match a registered user
if (users.HasKey(GuiControlGet(Username)) && users[GuiControlGet(Username)] = GuiControlGet(Password)) {
Gui, Submit, NoHide
MsgBox, Welcome %GuiControlGet(Username)%!
ExitApp
}
; If the login is unsuccessful, show an error message
MsgBox, Invalid username or password.
GuiControl,, Password,
GuiControlFocus, Password
Return
; Function to handle the register button click
Register:
; Show the register GUI
ShowRegister()
Return
; Function to show the register GUI
ShowRegister() {
Gui, +AlwaysOnTop
Gui, Add, Text, vNewUsername x20 y20, New username:
Gui, Add, Edit, vNewUsername x100 y20 w150,
Gui, Add, Text, vNewPassword x20 y50, New password:
Gui, Add, Edit, vNewPassword x100 y50 w150 password,
Gui, Add, Button, gCreateAccount x20 y80, Create Account
Gui, Add, Button, gCancel x150 y80, Cancel
Gui, Show
}
; Function to handle the create account button click
CreateAccount:
; Check if the new username is already taken
if (users.HasKey(GuiControlGet(NewUsername))) {
MsgBox, This username is already taken.
GuiControl,, NewUsername,
GuiControlFocus, NewUsername
Return
}
; Add the new user to the list of registered users
users[GuiControlGet(NewUsername)] := GuiControlGet(NewPassword)
; Show a success message and return to the login GUI
MsgBox, Your account has been created.
Gui, Submit, NoHide
ShowLogin()
Return
; Function to handle the cancel button click
Cancel:
; Return to the login GUI
Gui, Submit, NoHide
ShowLogin()
Return