Jump to content

Login And Password Before Showing GUI


Go to solution Solved by Geir1983,

Recommended Posts

I have two separate scripts currently that I would like to merge into one.

I would like for the correct username and password to have to be entered before the GUI for the second script is displayed. Below are the two scripts, can someone explain to me how to do this... Thank you in advance for any help.

Script 1: Login (Username & Password) - Script I would like displayed first.

$GUI = GUICreate("Login",210,80,-1,-1,0x16C80000,0x00000181)
$USERNAME = GUICtrlCreateInput("Type here username",5,5,200,20,0x01)
$PASSWORD = GUICtrlCreateInput("Password",5,30,200,20,0x21)
$LOGIN = GUICtrlCreateButton("Login",50,55,100,20)
GUISetState(@SW_SHOW,$GUI)

While 1
    $MSG = GUIGetMsg()
    If $MSG = $LOGIN Then
        If GUICtrlRead($USERNAME) == "1" And GUICtrlRead($PASSWORD) == "1" Then
            ;Assuming 2nd GUI goes here some how
        Else
            MsgBox(0,"Login","Incorrect username or password.")
        EndIf
    ElseIf $MSG = -3 Then
        Exit
    EndIf
    Sleep(20)
WEnd

Script 2: A Slider Settings Script - Script I would like to show second and only if the username and password from script 1 were provided correctly.

 

#include <GUIConstantsEx.au3>
#Include <GuiSlider.au3>

Global $hGui, $iSlider, $iLabel, $nMsg
Global $iOld = 0, $iCur = 0

$hGui = GUICreate("Slider test", 500, 500, -1, -1)
$iSlider = GUICtrlCreateSlider(50, 30, 180, 20, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS))
GUICtrlSetLimit(-1, 4000, 1000)
$iLabel = GUICtrlCreateInput( GUICtrlRead($iOld), 40, 80, 100, 20)
$Button = GUICtrlCreateButton("Button", 150, 80, 100, 20)
GUISetState(@SW_SHOW, $hGui)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iSlider
         
         Case $Button
         $ShowMessag = MsgBox(0,"Title", GUICtrlRead($iLabel))
         
        Case Else
            $iCur = GUICtrlRead($iSlider)
            If $iOld <> $iCur Then
                $iOld = $iCur
                GUICtrlSetData($iLabel, "" & $iOld)
             EndIf
            
             
    EndSwitch
WEnd
Edited by jbsoccerbrit
Link to comment
Share on other sites

  • Solution

Quick and dirty:

#include <GUIConstantsEx.au3>
#include <GuiSlider.au3>



$GUI = GUICreate("Login", 210, 80, -1, -1, 0x16C80000, 0x00000181)
$USERNAME = GUICtrlCreateInput("Type here username", 5, 5, 200, 20, 0x01)
$PASSWORD = GUICtrlCreateInput("Password", 5, 30, 200, 20, 0x21)
$LOGIN = GUICtrlCreateButton("Login", 50, 55, 100, 20)
GUISetState(@SW_SHOW, $GUI)


Local $LoggedIn
While Not $LoggedIn

    $MSG = GUIGetMsg()

    If $MSG = $LOGIN Then

        If GUICtrlRead($USERNAME) == "1" And GUICtrlRead($PASSWORD) == "1" Then
            $LoggedIn = TRUE
            GUIDelete($GUI) 
            ;Assuming 2nd GUI goes here some how
        Else
            MsgBox(0, "Login", "Incorrect username or password.")

        EndIf

    ElseIf $MSG = -3 Then

        Exit

    EndIf

    Sleep(20)

WEnd



Global $hGui, $iSlider, $iLabel, $nMsg
Global $iOld = 0, $iCur = 0

$hGui = GUICreate("Slider test", 500, 500, -1, -1)
$iSlider = GUICtrlCreateSlider(50, 30, 180, 20, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS))
GUICtrlSetLimit(-1, 4000, 1000)
$iLabel = GUICtrlCreateInput(GUICtrlRead($iOld), 40, 80, 100, 20)
$Button = GUICtrlCreateButton("Button", 150, 80, 100, 20)
GUISetState(@SW_SHOW, $hGui)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iSlider

        Case $Button
            $ShowMessag = MsgBox(0, "Title", GUICtrlRead($iLabel))

        Case Else
            $iCur = GUICtrlRead($iSlider)
            If $iOld <> $iCur Then
                $iOld = $iCur
                GUICtrlSetData($iLabel, "" & $iOld)
            EndIf


    EndSwitch
WEnd
Link to comment
Share on other sites

Put script 2 below script 1 while loop and replace ";Assuming 2nd GUI goes here some how" with "ExitLoop"

EDIT: sorry as above GUIDelete first and then Exitloop.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I made a login script once that requires an internet connection, its messy as hell and probably have tons of extra/uneeded code, feel free to try it

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <Inet.au3>
#include <Misc.au3>

Global $hDLL
$hGUI = GUICreate("Login", 237, 139, -1, -1, $WS_POPUPWINDOW)
$hInput = GUICtrlCreateInput("", 65, 15, 100, 25, $ES_CENTER)
GUICtrlSetFont(-1, 8.5, 400, 0, "Palatino Linotype", 5)
$hInput2 = GUICtrlCreateInput("", 66, 45, 100, 25, $ES_PASSWORD + $ES_CENTER)
GUICtrlSetFont(-1, 8.5, 400, 0, "Palatino Linotype", 5)
$hLabel = GUICtrlCreateLabel("", 0, 115, 230, 22)
GUICtrlSetFont(-1, 8.5, 400, 0, "Palatino Linotype", 5)
GUICtrlSetStyle(-1, $SS_CENTER)
$online = GUICtrlCreateLabel("", 0, 0, 237, 6)
GUICtrlSetBkColor(-1, 0x41CE39)
GUICtrlSetState(-1, $GUI_HIDE)
$offline = GUICtrlCreateLabel("", 0, 0, 237, 6)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetBkColor(-1, 0xF00B22)
$online1 = GUICtrlCreateLabel("", 0, 133, 237, 6)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetBkColor(-1, 0x41CE39)
$offline1 = GUICtrlCreateLabel("", 0, 133, 237, 6)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetBkColor(-1, 0xF00B22)
GUISetBkColor(0xDBECF9)
$online2 = GUICtrlCreateLabel("", 231, 0, 6, 139)
GUICtrlSetBkColor(-1, 0x41CE39)
GUICtrlSetState(-1, $GUI_HIDE)
$online3 = GUICtrlCreateLabel("", 0, 0, 6, 139)
GUICtrlSetBkColor(-1, 0x41CE39)
GUICtrlSetState(-1, $GUI_HIDE)
$offline2 = GUICtrlCreateLabel("", 0, 0, 6, 139)
GUICtrlSetBkColor(-1, 0xF00B22)
GUICtrlSetState(-1, $GUI_HIDE)
$offline3 = GUICtrlCreateLabel("", 231, 0, 6, 139)
GUICtrlSetBkColor(-1, 0xF00B22)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState()

_Server_Status()

Func _Server_Status()
    $hDLL = DllOpen("user32.dll")
    Local $status = InetRead("http://www.yourwebsite.com/online.dat", $INET_FORCERELOAD) ; Add a file called "online.dat" to your website, write "online" or "offline" inside that file without the quotes to determin the server status
    Switch $status
        Case "offline"
            GUICtrlSetState($offline, $GUI_Show)
            GUICtrlSetState($offline1, $GUI_Show)
            GUICtrlSetState($offline2, $GUI_Show)
            GUICtrlSetState($offline3, $GUI_Show)
        Case "online"
            GUICtrlSetState($online, $GUI_Show)
            GUICtrlSetState($online1, $GUI_Show)
            GUICtrlSetState($online2, $GUI_Show)
            GUICtrlSetState($online3, $GUI_Show)
        Case Else
            GUICtrlSetData($hLabel, "Server offline")
            GUICtrlSetState($offline, $GUI_Show)
            GUICtrlSetState($offline1, $GUI_Show)
            GUICtrlSetState($offline2, $GUI_Show)
            GUICtrlSetState($offline3, $GUI_Show)
    EndSwitch
EndFunc   ;==>_Server_Status

Local $status = InetRead("http://www.yourwebsite.com/online.dat", $INET_FORCERELOAD)
If @error Then
    GUICtrlSetData($hLabel, "Server offline / Check Internet Connection")
    GUICtrlSetState($offline, $GUI_Show)
    GUICtrlSetState($offline1, $GUI_Show)
    GUICtrlSetState($offline2, $GUI_Show)
    GUICtrlSetState($offline3, $GUI_Show)
    Sleep(500)
EndIf

$saveduser = RegRead("HKEY_CURRENT_USER\Software\Login", "Main Log Name")
GUICtrlSetData($hInput, $saveduser)
$comeone = GUICtrlRead($hInput)
If $comeone <> "" Then
    GUICtrlSetState($hInput2, $GUI_FOCUS)
Else
    GUICtrlSetState($hInput, $GUI_FOCUS)
EndIf

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    While 1
        If _IsPressed("0D", $hDLL) Then
            $startuser = GUICtrlRead($hInput)
            $OfflineChecker = GUICtrlRead($hLabel)
            RegWrite("HKEY_CURRENT_USER\Software\Login", "Main Log Name", "REG_SZ", $startuser)
            If $status = "offline" Then
                GUICtrlSetData($hLabel, "Server offline, Try again later")
                Sleep(3000)
                Exit
            EndIf
            GUICtrlSetData($hLabel, "Logging in, Please wait..")
            Local $bData = InetGetSize("http://www.yourwebsite.com/" & $startuser & ".dat", $INET_FORCERELOAD) ; Add a ".dat" file in your website, the filename is the username and whatever is written inside it is the password for that username
            While 1
                Switch $bData
                    Case "0"
                        $OfflineChecker = GUICtrlRead($hLabel)
                        If $OfflineChecker = "Server offline / Check Internet Connection" Then
                            GUICtrlSetData($hLabel, "Unable to connect")
                            ExitLoop
                        Else
                            GUICtrlSetData($hLabel, "Invalid Username/Password.")
                            ContinueCase
                        EndIf
                    Case Else
                        Local $userpass = InetRead("http://www.yourwebsite.com/" & $startuser & ".dat", $INET_FORCERELOAD)
                        If @error Then
                            GUICtrlSetData($hLabel, "Server offline / Check Internet Connection")
                            GUICtrlSetState($offline, $GUI_Show)
                            GUICtrlSetState($offline1, $GUI_Show)
                            GUICtrlSetState($offline2, $GUI_Show)
                            GUICtrlSetState($offline3, $GUI_Show)
                            Sleep(500)
                        EndIf
                        $guipass = GUICtrlRead($hInput2)
                        If $userpass = $guipass Then
                        Else
                            GUICtrlSetData($hLabel, "Invalid Username/Password..")
                            ExitLoop
                        EndIf
                        GUICtrlSetData($hLabel, "Logged in successfully")
                        Sleep(1000)
                        GUIDelete()
                        ExitLoop (2)

                EndSwitch
            WEnd
        EndIf
        If _IsPressed("1B", $hDLL) Then
            Exit
        EndIf
    WEnd
WEnd


; Your 2nd script goes here

Click Enter to login, or Esc to exit.

Edited by Palestinian
Link to comment
Share on other sites

#include <Crypt.au3>
; Way to create a password
; $password='New password'
; $bEncrypted = _Crypt_EncryptData($password, $password, $CALG_AES_192)
; MsgBox(0, 'Encryption password', $bEncrypted)
; ClipPut($bEncrypted)

; for the program
$bEncrypted = '0x6DF6DD99DA8A91EA8366BB3C2E89CFDA' ; password: Hello
Do
    $pass = InputBox('Password', 'Enter the password', '', '*', 100, 130)
    If @error Then Exit
Until $pass == BinaryToString(_Crypt_DecryptData($bEncrypted, $pass, $CALG_AES_192))
MsgBox(0, 'Password', 'The password is correct - ' & $pass)

'?do=embed' frameborder='0' data-embedContent>>

#include <GUIConstantsEx.au3>
#include <GuiSlider.au3>

_Login()

Func _Login()
    Local $hGUI, $iLogin, $iPassword, $iUserName

    $hGUI = GUICreate("Login", 210, 80, -1, -1, 0x16C80000, 0x00000181)
    $iUserName = GUICtrlCreateInput("Type here username", 5, 5, 200, 20, 0x01)
    $iPassword = GUICtrlCreateInput("Password", 5, 30, 200, 20, 0x21)
    $iLogin = GUICtrlCreateButton("Login", 50, 55, 100, 20)
    GUISetState(@SW_SHOW, $hGUI)
    
    While 1
        Switch GUIGetMsg()
            Case $iLogin
                If GUICtrlRead($iUserName) = "Type here username" And GUICtrlRead($iPassword) = "Password" Then
                    GUIDelete()
                    ExitLoop
                Else
                    MsgBox(0, "Login", "Incorrect username or password.")
                EndIf
            Case -3
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>_FuncName

Global $hGUI, $iSlider, $iLabel, $nMsg
Global $iOld = 0, $iCur = 0

$hGUI = GUICreate("Slider test", 500, 500, -1, -1)
$iSlider = GUICtrlCreateSlider(50, 30, 180, 20, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS))
GUICtrlSetLimit(-1, 4000, 1000)
$iLabel = GUICtrlCreateInput(GUICtrlRead($iOld), 40, 80, 100, 20)
$Button = GUICtrlCreateButton("Button", 150, 80, 100, 20)
GUISetState(@SW_SHOW, $hGUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iSlider

        Case $Button
            $ShowMessag = MsgBox(0, "Title", GUICtrlRead($iLabel))

        Case Else
            $iCur = GUICtrlRead($iSlider)
            If $iOld <> $iCur Then
                $iOld = $iCur
                GUICtrlSetData($iLabel, "" & $iOld)
            EndIf

    EndSwitch
WEnd
Edited by AZJIO
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...