Jump to content

Username and password GUI


Recommended Posts

Hey guys, I am working on a GUI to capture a user's login credentials and then stay up while some system settings are made on the client machine that are needed for our remote VPN users. I know I can't (or don't need to) authenticate back to AD, but I want basic validation (is username blank? do both password fields equal?). The script runs fine but I am not sure if there is a better way. I would be very appreciative for any hints / tips you could provide on my coding.

#include <GUIConstants.au3>
$version = "2.0"

GuiCreate("HHCS VPN Setup   v" & $version, 392, 316,-1, -1)

$user = GuiCtrlCreateInput("", 150, 100, 200, 20)
$passw = GuiCtrlCreateInput("", 150, 140, 200, 20, $ES_PASSWORD)
$pass2 = GuiCtrlCreateInput("", 150, 180, 200, 20, $ES_PASSWORD)
$OK = GuiCtrlCreateButton("OK", 160, 230, 60, 30)
$userLbl = GuiCtrlCreateLabel("Username:", 30, 105, 111, 30, $SS_RIGHT )
$passLbl = GuiCtrlCreateLabel("Password:", 30, 145, 111, 30, $SS_RIGHT )
$passLbl2 = GuiCtrlCreateLabel("Confirm Password:", 30, 185, 111, 30, $SS_RIGHT )
$Icon = GuiCtrlCreateIcon("hmc2.ico", 0, 20, 10, 50, 50)
$HeaderLbl = GuiCtrlCreateLabel("HHCS VPN Setup", 70, 8, 280, 70)
GUICtrlSetFont (-1,24, 600, 0, "Arial")
$versionlbl = GuiCtrlCreateLabel("Version " & $version, 170, 60, 80, 23)

GuiSetState()

While 1
    $msg = GuiGetMsg() 
    Select
    Case $msg = $OK and GUICtrlRead($user) = "" 
    msgbox(0,"Error", "No Username Has Been Entered")
    Case $msg = $OK and GUICtrlRead($user) <> "" and GUICtrlRead($passw) <> GUICtrlRead($pass2)
    msgbox(0,"Error", "Password Not Confirmed - Please Enter Again")
    GUICtrlSetData ( $passw, "" )
    GUICtrlSetData ( $pass2, "" )
    ControlFocus("HHCS VPN Setup", "", $passw)
    Case $msg = $OK and GUICtrlRead($user) <> "" and GUICtrlRead($passw) = GUICtrlRead($pass2)
    Call ("Cont_Program")
    Case $msg = $GUI_EVENT_CLOSE
    Call("Prog_Exit")
    EndSelect
Sleep(50)
WEnd    

Exit

;-------------- Functions ----------------------

My functions work fine, so I won't bore you with them.

Thanks,

MuffinMan

Edited by MuffinMan
Link to comment
Share on other sites

Thanks for the feedback, valuater, I actually looked through a lot of your "hobby" scripts for help on some of this stuff for the past few days. I'll make those call changes like you and Liope suggested.

Edited by MuffinMan
Link to comment
Share on other sites

Thanks for the feedback, valuater, I actually looked through a lot of your "hobby" scripts for help on some of this stuff for the past few days. I'll make those call changes like you and Liope suggested.

HI,

I think your script works perfectly fine. But I don´t like "breaking" the GUI by sending messages with MsgBox...

Maybe you could create a label at the buttom of the GUI which points out what is going on.

E.g. "No Username Has Been Entered" and so on.

Just think about it. :lmao:

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Great idea, th.meger - I guess I would just set a label initially valued as "" and then revalue it when there's an error?

Thanks,

here is an old GUI I made, maybe it helps. Although the texts are in German... :lmao:

#include <GUIConstants.au3>
Opt("WinTitleMatchMode", 2)

HotKeySet("{F10}", "terminate")
$string = @ScriptDir
$string2 = StringReplace($string, "\", "//")
$string3 = StringTrimLeft($string2, 4)
$Form1 = GUICreate("PCInfo --- Version 2.0", 370, 280, 210, 125)
GUICtrlCreateLabel("PcInfo --- Hauptmenü", 25, 20, 350, 95)
$Group1 = GUICtrlCreateGroup("Die Buttons", 20, 112, 330, 125)
$Button1 = GUICtrlCreateButton("Transfer PCInfo2.0.exe", 30, 140, 140, 25)
$Button2 = GUICtrlCreateButton("Start PCInfo2.0.exe", 30, 170, 140, 25)
$Button3 = GUICtrlCreateButton("Start FTP", 30, 200, 140, 25)
$Button4 = GUICtrlCreateButton("Rename Folder", 200, 140, 140, 25)
$Button5 = GUICtrlCreateButton("Delete PCInfo2.0.exe", 200, 170, 140, 25)
$Button6 = GUICtrlCreateButton("Quit ", 200, 200, 140, 25)
GUICtrlCreateLabel("Status", 25, 250, 350, 40)
GUICtrlCreateGroup("ToDo: ", 20 , 4, 330, 100)
GUISetState(@SW_SHOW)

$counter = 3

While 1
    $msg = GUIGetMsg()
    If $counter = 3 Then
        Sleep(1000)
        GUICtrlSetData(11, "Initialisiere... " & $counter)
        $counter = $counter - 1
    ElseIf $counter = 2 Then
        Sleep(1000)
        GUICtrlSetData(11, "Initialisiere... " & $counter)
        $counter = $counter - 1
    ElseIf $counter = 1 Then
        Sleep(1000)
        GUICtrlSetData(11, "Initialisiere... " & $counter)
        $counter = $counter - 1
    ElseIf $counter = 0 Then
        Sleep(1000)
        GUICtrlSetData(11, "Bereit ...")
        $counter = $counter - 1
        GUICtrlSetData(3, "Wechseln Sie in den FTP-Mode" _
                 & @CRLF & "Befehl: exit; mode ft;" & @CRLF & "Drücken Sie anschließend 'Transfer PCInfo.exe'")
    ElseIf $counter < 0 Then
        
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button1
                copyPCInfo()
                GUICtrlSetData(11, "Der Befehl für den File-Transfer wurde in die Zwischenablage kopiert")
                Sleep(5000)
                GUICtrlSetData(11, "Bereit ...")
                GUICtrlSetData(3, "Wechseln Sie in den RLS-Mode zurück" & @CRLF & "Befehl: mode rls; connect;" _
                         & @CRLF & "Drücken Sie nun 'Start PCInfo2.0.exe'")
            Case $msg = $Button2
                startPCInfo()
                GUICtrlSetData(11, "Der Befehl zum Start der PCInfo2.0.exe wurde in die Zwischenablage kopiert")
                Sleep(5000)
                GUICtrlSetData(11, "Bereit ...")
                GUICtrlSetData(3, "Wechseln Sie in den FTP-Mode zurück" & @CRLF & "Befehl: exit; mode ft;" & @CRLF _
                         & "Wenn Sie PCInfo ausgeführt haben, drücken Sie nun" _
                         & @CRLF & "'Start FTP'")
            Case $msg = $Button3
                startFtp()
                GUICtrlSetData(11, "Der Befehl zum File-Transfer des Zip-Files wurde in die Zwischenablage kopiert")
                Sleep(5000)
                GUICtrlSetData(11, "Bereit ...")
                GUICtrlSetData(3, "Das Zip-File wurde in den lokalen Ordner, " & @CRLF & @ScriptDir & "\PCInfo kopiert" _
                         & @CRLF & "Um den Ordner zu individualisieren drücken Sie 'Rename Folder'")
            Case $msg = $Button4
                renameFolder()
                GUICtrlSetData(11, "Der Ordner wurde umbenannt/individualisiert")
                Sleep(5000)
                GUICtrlSetData(11, "Bereit ...")
                GUICtrlSetData(3, "Wechseln Sie in den RLS-Mode zurück" & @CRLF & "Befehl: mode rls; connect;" _
                         & @CRLF & "Drücken Sie nun 'Delete PcInfo2.0.exe'")
            Case $msg = $Button5
                delete()
                GUICtrlSetData(11, "Der Befehl zum Löschen der 'PCInfo.zip' Datei wurde in die Zwischenablage kopiert")
                Sleep(5000)
                GUICtrlSetData(11, "Bereit ...")
                GUICtrlSetData(3, "Vielen Dank!!!" & @CRLF & "Das Programm kann jetzt über 'Quit'" _
                         & @CRLF & "beendet werden")
            Case $msg = $Button6
                GUICtrlSetData(11, "So long, " & @CRLF & "Mega")
                Sleep(2000)
                terminate()
            Case Else
        EndSelect
    EndIf
WEnd
Exit

Func copyPCInfo()
    ClipPut("put v://" & $string3 & "//PcInfoTM2.0.exe c://winnt//temp//PcInfoTM2.0.exe")
EndFunc  ;==>copyPCInfo

Func startPCInfo()
    ClipPut("start c:\winnt\temp\PCInfoTM2.0.exe delete folderTree")
EndFunc  ;==>startPCInfo

Func startFtp()
    DirCreate($string & "\PCInfo2.0")
    ClipPut("get c://winnt//temp//" & "TM_PCInfo2.0.zip v://" & $string3 & "//PCinfo2.0//" & "TM_PCInfo2.0.zip")
EndFunc  ;==>startFtp

Func renameFolder()
    DirMove($string & "\PCInfo2.0", $string & "\PCInfo2.0_" & @MDAY & "-" & @MON & "-" & @YEAR & "_-_" & @HOUR & "-" & @MIN & "-" & @SEC)
EndFunc  ;==>renameFolder

Func delete()
    ClipPut("del c:\winnt\temp\TM_*.zip")
EndFunc  ;==>delete

Func terminate()
    Exit (0)
EndFunc  ;==>terminate

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Mega,

I will definitely pour through that code soon, but I was able to set a label below my OK button and just change the label's text as there are errors. Once there are no errors, I set the label back to "" and then add my progress bar on top for the rest of the script. It does look much more professional than the msgbox I was using. Thanks for the feedback!

Edited by MuffinMan
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...