Manjish Posted February 13, 2009 Share Posted February 13, 2009 Ppl, Here's my code: expandcollapse popup#include <EditConstants.au3> $file=FileOpen("c:\db.ini",1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 436, 221, 193, 125) $Group1 = GUICtrlCreateGroup("Make A Choice", 0, 0, 433, 217) $Button1 = GUICtrlCreateButton("Register", 24, 152, 169, 33, 0) $Button2 = GUICtrlCreateButton("Login", 240, 152, 169, 33, 0) $Label1 = GUICtrlCreateLabel("What Do You Wish To Do?", 136, 72, 135, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() if $nMsg=$GUI_EVENT_CLOSE then ExitLoop If $nMsg=$Button1 then Register() If $nMsg=$Button2 then Signin() WEnd Func Register() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 460, 293, 193, 125) $Group1 = GUICtrlCreateGroup("Register", 0, 0, 457, 289) $Label1 = GUICtrlCreateLabel("Enter Registration Information", 40, 48, 143, 17) $input1=GUICtrlCreateInput("", 208, 104, 233, 21) $Label2 = GUICtrlCreateLabel("Username", 48, 104, 52, 17) $Label3 = GUICtrlCreateLabel("Password", 48, 160, 50, 17) $input2=GUICtrlCreateInput("", 208, 160, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Button1 = GUICtrlCreateButton("OK", 160, 232, 169, 41, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() if $nMsg=$GUI_EVENT_CLOSE then ExitLoop If $nMsg=$Button1 then IniWriteSection($file,"Information","") IniWrite($file,"Information",guictrlread($input1),guictrlread($input2)) GUIDelete($Form1) Return EndIf WEnd EndFunc What i am trying to here is this: 1) user will be presented, with 2 buttons.. login and register.. 2) when they press register.. the values in input box will be written in an ini file as username=password.. 3) and when OK button is pressed on the Register GUI, I want it to close, and again go back to previous GUI, with the two buttons.. 4) Now when i again press Register, it shud again launch register GUI.. This can be done for as many times as possible.. But this is not happening.. Please help me with this one, thanks.. [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
BrettF Posted February 13, 2009 Share Posted February 13, 2009 Some what of an example. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> $file = "C:\db.ini" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 400, 200, 193, 125) $Group1 = GUICtrlCreateGroup("Make A Choice", 5, 5, 390, 190) $Button1 = GUICtrlCreateButton("Register", 15, 152, 170, 33, 0) $Button2 = GUICtrlCreateButton("Login", 215, 152, 170, 33, 0) $Label1 = GUICtrlCreateLabel("What Do You Wish To Do?", 136, 72, 135, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1;Register $ret = _GUICreateLogin("Enter Credentials", "Enter the username and password", -1, -1, -1, -1, -1, 10000) If @error Then MsgBox(0, "Error", "Error Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended) Else $check = _CheckUsername($file, $ret[0]) If Not $check Then IniWrite($file, "UserData", $ret[0], $ret[1]) Else MsgBox(0, "", "Username already exists!") EndIf EndIf Case $Button2;Login $ret = _GUICreateLogin("Enter Credentials", "Enter the username and password", -1, -1, -1, -1, -1, 10000) If @error Then MsgBox(0, "Error", "Error Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended) Else $check = _CheckUsername($file, $ret[0]) If $check Then $password = IniRead($file, "UserData", $ret[0], "") If Not @error And $password == $ret[1] Then MsgBox(0, "", "Credentials correct!") Exit Else MsgBox (0, "", "Incorect Credentials Entered!") EndIf EndIf EndIf EndSwitch WEnd ;=============================================================================== ; Function Name: _GUICreateLogin() ; Description: Create a basic login box with Username, Password, and a prompt. ; Syntax: ; Parameter(s): $hTitle - The title of the Form ; $hPrompt - The text prompt for the user [Optional] (maximum of 2 lines) ; $bBlank - The password or username can be blank. [optional] ; Default = False (Blanks are not allowed) ; $hWidth - Width of the form [optional] - default = 250 ; $hHeight - Height of the form [optional] - default = 130 ; $hLeft - X position [optional] - default = centered ; $hTop - Y position [optional] - default = centered ; $Timeout - The timeout of the form [optional - default = 0 (no timeout) ; $ShowError - Prompts are displayed to the user with timeout [optional] ; Requirement(s): None ; Return Value(s): Success - Returns an array of 2 elements where ; [0] = UserName ; [1] = Password ; Failure - Sets @Error to 1 and ; @Extended - 1 = Cancel/Exit Button Pressed ; - 2 = Timed out ; Author(s): Brett Francis (exodus.is.me@hotmail.com) ; Modification(s): GeoSoft ; Note(s): If $hPrompt is blank then the GUI height will be reduced by 30 ; Example(s): ;=============================================================================== Func _GUICreateLogin($hTitle = "Credentials Required", $hPrompt = "", $bBlank = False, $hWidth = -1, $hHeight = -1, $hLeft = -1, $hTop = -1, $timeout = 0, $ShowError = 0) $iGCM = Opt("GUICoordMode", 2);; Get the current value of GUICoordMode and set it to 2 If StringRegExp($bBlank, "(?i)\s|default|-1") Then $bBlank = False If StringRegExp($hWidth, "(?i)\s|default|-1") Then $hWidth = 250 If StringRegExp($hHeight, "(?i)\s|default|-1") Then $hHeight = 130 If StringRegExp($hLeft, "(?i)\s|default|-1") Then $hLeft = (@DesktopWidth / 2) - ($hWidth / 2) If StringRegExp($hTop, "(?i)\s|default|-1") Then $hTop = (@DesktopHeight / 2) - ($hHeight / 2) If Not $hPrompt Then $hHeight -= 30;If $hPrompt is blank then resize the GUI. Local $retarr[2] = ["", ""], $Time = 0 Local $gui = GUICreate($hTitle, $hWidth, $hHeight, $hLeft, $hTop) GUISetCoord(4, 0) If $hPrompt Then Local $Lbl_Prompt = GUICtrlCreateLabel($hPrompt, -1, 4, 201, 30) Local $Lbl_User = GUICtrlCreateLabel("Username:", -1, 4, 64, 17);44, 64, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Local $username = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21) GUICtrlCreateLabel("Password:", -($hWidth - 8), 4, 65, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Local $password = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21, 32);, $ES_PASSWORD) GUISetCoord(($hWidth / 2) - 85, $hHeight - 34) Local $Btn_OK = GUICtrlCreateButton("&OK", -1, -1, 75, 25) Local $Btn_Cancel = GUICtrlCreateButton("&Cancel", 20, -1, 75, 25) GUICtrlSetState($Btn_OK, 512) GUISetState() If $timeout Then $Time = TimerInit() While 1 $Msg = GUIGetMsg() Local $sUser = GUICtrlRead($username) Local $sPass = GUICtrlRead($password) If ($Time And TimerDiff($Time) >= $timeout) And ($sUser = "" And $sPass = "") Then $Status = 2 ExitLoop EndIf Select Case $Msg = -3 $Status = 0 ExitLoop Case $Msg = $Btn_OK If $bBlank And ($sUser = "" Or $sPass = "") Then $Status = 1 ExitLoop Else If $sUser <> "" And $sPass <> "" Then $Status = 1 ExitLoop Else Select Case $sUser = "" And $sPass = "" If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!") Case $sPass = "" If $ShowError = 1 Then MsgBox(16, "Error!", "Password cannot be blank!") GUICtrlSetState($password, 256) Case $sUser = "" If $ShowError = 1 Then MsgBox(16, "Error!", "Username cannot be blank!") GUICtrlSetState($username, 256) EndSelect EndIf EndIf Case $Msg = $Btn_Cancel $Status = 0 ExitLoop Case $timeout And TimerDiff($Time) >= $timeout; And $timeout If $bBlank And ($sUser = "" Or $sPass = "") Then $Status = 2 ExitLoop Else ;$time = TimerInit() Select Case $sUser = "" And $sPass = "" If $timeout Then $Time = TimerInit() If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!") Case $sPass = "" If $timeout Then $Time = TimerInit() If $ShowError = 1 Then MsgBox(16, "Error!", "Password cannot be blank!") GUICtrlSetState($password, 256) EndIf Case $sUser = "" $Time = TimerInit() If $ShowError = 1 Then MsgBox(16, "Error!", "Username cannot be blank!") GUICtrlSetState($username, 256) EndIf ;Case ($Timeout AND TimerDiff($time) >= $timeout) AND ($sUser = "" OR $sPass = "") ;$status = 2 ;ExitLoop Case Else If $sUser <> "" And $sPass <> "" Then $Status = 3 ;If $Timeout AND TimerDiff($time) >= $timeout Then $Status = 2 ExitLoop EndIf EndSelect EndIf EndSelect WEnd Local $eMsg = "" Switch $Status Case 0, 2 $err = 1;0 $ext = 1;Cancel/Exit Button Pressed $eMsg = "Cancel/Exit Button Pressed" If $Status = 2 Then $ext = 2;Timed Out If $ext = 2 Then $eMsg = "Timed Out" Case Else;1, 3 $retarr[0] = $sUser $retarr[1] = $sPass $err = 0;1 $ext = 0 If $Status = 3 Then $ext = 1;Username Fields Not Blank, Timeout reached EndSwitch GUIDelete($gui) Opt("GUICoordMode", $iGCM);Reset the GUICoordMode to what it started as. If $eMsg Then Return SetError($err, $ext, $eMsg) Return $retarr EndFunc ;==>_GUICreateLogin Func _CheckUsername($file, $username) $var = IniReadSection($file, "UserData") If @error Then Return 0 Else For $i = 1 To $var[0][0] If StringInStr($var[$i][0], $username, 1) Then Return 1 Next Return 0 EndIf EndFunc ;==>_CheckUsername Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Author Share Posted February 13, 2009 Thanks a lot.. it works just the way i want it to.. Wasn't aware of the UDF.. thanks for your help.. Now i am going to write the code for the signin part.. will post again if i need any help.. thanks, n bye [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Author Share Posted February 13, 2009 oh... u already took care of the login part?? oh.. wasn't aware of it. thanks anyways.. [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Spiff59 Posted February 13, 2009 Share Posted February 13, 2009 expandcollapse popup#include <EditConstants.au3> #include <GUIConstants.au3> ;$file=FileOpen("c:\db.ini",1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 436, 221, 193, 125) $Group1 = GUICtrlCreateGroup("Make A Choice", 0, 0, 433, 217) $Button1 = GUICtrlCreateButton("Register", 24, 152, 169, 33, 0) $Button2 = GUICtrlCreateButton("Login", 240, 152, 169, 33, 0) $Label1 = GUICtrlCreateLabel("What Do You Wish To Do?", 136, 72, 135, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() if $nMsg=$GUI_EVENT_CLOSE then ExitLoop If $nMsg=$Button1 then Register() ; If $nMsg=$Button2 then Signin() WEnd Exit Func Register() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 460, 293, 193, 125) $Group1 = GUICtrlCreateGroup("Register", 0, 0, 457, 289) $Label1 = GUICtrlCreateLabel("Enter Registration Information", 40, 48, 143, 17) $input1=GUICtrlCreateInput("", 208, 104, 233, 21) $Label2 = GUICtrlCreateLabel("Username", 48, 104, 52, 17) $Label3 = GUICtrlCreateLabel("Password", 48, 160, 50, 17) $input2=GUICtrlCreateInput("", 208, 160, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Button3 = GUICtrlCreateButton("OK", 160, 232, 169, 41, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() if $nMsg=$GUI_EVENT_CLOSE then ExitLoop If $nMsg=$Button3 then ; IniWriteSection($file,"Information","") ; IniWrite($file,"Information",guictrlread($input1),guictrlread($input2)) ExitLoop EndIf WEnd GUIDelete($Form1) EndFunc The second While loop works a little better this way I think. Your main trouble was that the second GUI was trashing Button1 from the first GUI, renaming it to Button3 like above seems to have the linkage working like you require. Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Author Share Posted February 13, 2009 @spiff59.. Oh, now i get it.. thanks.. actually i made those two gui's in koda.. so had the same variable names.. thanks, for ur help.. appreciate it greatly [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Author Share Posted February 13, 2009 hey brett, Hey I was just looking very closely at the script u sent me.. in the function "_CheckUsername($file, $username)" y have u put this: If StringInStr($var[$i][0], $username, 1) Then Return 1 what it does is if i register with username "manjish1" and then try to register with "manjish", it says that username already exists.. That's because of "stringinstr".. is there any specific reason y u put this?? [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Author Share Posted February 13, 2009 hey i wrote just completed the script.. here it is.. thanks Brett and Spiff59.. expandcollapse popup#include <EditConstants.au3> #include <GUIConstants.au3> $file = "C:\db.ini" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 436, 221, 193, 125) $Group1 = GUICtrlCreateGroup("Make A Choice", 0, 0, 433, 217) $Button1 = GUICtrlCreateButton("Register", 24, 152, 169, 33, 0) $Button2 = GUICtrlCreateButton("Login", 240, 152, 169, 33, 0) $Label1 = GUICtrlCreateLabel("What Do You Wish To Do?", 136, 72, 135, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() if $nMsg=$GUI_EVENT_CLOSE then ExitLoop If $nMsg=$Button1 then Register() If $nMsg=$Button2 then Signin() WEnd Exit Func Register() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 460, 293, 193, 125) $Group1 = GUICtrlCreateGroup("Register", 0, 0, 457, 289) $Label1 = GUICtrlCreateLabel("Enter Registration Information", 40, 48, 143, 17) $input1=GUICtrlCreateInput("", 208, 104, 233, 21) $Label2 = GUICtrlCreateLabel("Username", 48, 104, 52, 17) $Label3 = GUICtrlCreateLabel("Password", 48, 160, 50, 17) $input2=GUICtrlCreateInput("", 208, 160, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Button3 = GUICtrlCreateButton("OK", 160, 232, 169, 41, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() if $nMsg=$GUI_EVENT_CLOSE then ExitLoop If $nMsg=$Button3 then $check=_CheckUsername($file,GUICtrlRead($input1)) If Not $check Then IniWrite($file, "UserData", GUICtrlRead($input1), GUICtrlRead($input2)) Else MsgBox(0, "", "Username already exists!") EndIf ExitLoop EndIf WEnd GUIDelete($Form1) EndFunc Func Signin() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 460, 293, 193, 125) $Group1 = GUICtrlCreateGroup("Register", 0, 0, 457, 289) $Label1 = GUICtrlCreateLabel("Enter Registration Information", 40, 48, 143, 17) $input1=GUICtrlCreateInput("", 208, 104, 233, 21) $Label2 = GUICtrlCreateLabel("Username", 48, 104, 52, 17) $Label3 = GUICtrlCreateLabel("Password", 48, 160, 50, 17) $input2=GUICtrlCreateInput("", 208, 160, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Button4 = GUICtrlCreateButton("OK", 160, 232, 169, 41, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() if $nMsg=$GUI_EVENT_CLOSE then ExitLoop If $nMsg=$Button4 then $check = _CheckUsername($file, GUICtrlRead($input1)) If $check Then $password = IniRead($file, "UserData", GUICtrlRead($input1), "") If Not @error And $password == GUICtrlRead($input2) Then MsgBox(0, "", "Credentials correct!") Exit Else MsgBox (0, "", "Incorect Credentials Entered!") EndIf EndIf ExitLoop EndIf WEnd GUIDelete($Form1) EndFunc Func _CheckUsername($file, $username) $var = IniReadSection($file, "UserData") If @error Then Return 0 Else For $i = 1 To $var[0][0] If $var[$i][0]=$username Then Return 1 Next Return 0 EndIf EndFunc ;==>_CheckUsername Please tell me what u think about it.. Spiff, please clean this one up, if u feel anything's unnecessary.. i'll definately incorporate ur suggestions.. [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 13, 2009 Moderators Share Posted February 13, 2009 Manjish,Thank you for asking me to take a look - works a treat. Could I make 1 comment and 2 suggestions?Comment. Save the .ini file elsewhere than C:\. Vista can get very upset if you start creating/deleting files there as I know to my cost! Perhaps @ScriptDir might be a good solution?Suggestion 1. As a matter of personal preference I use Switch statements for GUIGetMsg loops:While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 Register() Case $Button2 Signin() EndSwitch WEnd ; Rather than: While 1 $nMsg = GUIGetMsg() if $nMsg=$GUI_EVENT_CLOSE then ExitLoop If $nMsg=$Button1 then Register() If $nMsg=$Button2 then Signin() WEndEverthing stands out clearly when SciTE does its syntax colouring trick and so I find it easier to look through if you end up with a lot of controls to manage. The only exception is when I have to use the advanced parameter and GUIGetMsg returns an array - but I try to avoid that as much as possible.Suggestion 2. Encrypt the password!M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Author Share Posted February 13, 2009 (edited) Comment. Save the .ini file elsewhere than C:\. Vista can get very upset if you start creating/deleting files there as I know to my cost! Perhaps @ScriptDir might be a good solution? A good point.. Thanks, will definately incorporate it.. As a matter of personal preference I use Switch statements for GUIGetMsg loops:I know it saves a lot of code, and also looks nice. n u don't have to keep on ending ur ifs.. just need to end ur switch. Another good point.. Will Incorporate it.. Suggestion 2. Encrypt the password!had crossed my mind.. can u help, I don't know how to encrypt.. will love to incorporate this 1 too.. coz i don't want ppl looking at my passwords. Here's the script with comment and suggestion 1.. expandcollapse popup#include <EditConstants.au3> #include <GUIConstants.au3> $file = "db.ini" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 436, 221, 193, 125) $Group1 = GUICtrlCreateGroup("Make A Choice", 0, 0, 433, 217) $Button1 = GUICtrlCreateButton("Register", 24, 152, 169, 33, 0) $Button2 = GUICtrlCreateButton("Login", 240, 152, 169, 33, 0) $Label1 = GUICtrlCreateLabel("What Do You Wish To Do?", 136, 72, 135, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 Register() Case $Button2 Signin() EndSwitch WEnd Exit Func Register() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 460, 293, 193, 125) $Group1 = GUICtrlCreateGroup("Register", 0, 0, 457, 289) $Label1 = GUICtrlCreateLabel("Enter Registration Information", 40, 48, 143, 17) $input1=GUICtrlCreateInput("", 208, 104, 233, 21) $Label2 = GUICtrlCreateLabel("Username", 48, 104, 52, 17) $Label3 = GUICtrlCreateLabel("Password", 48, 160, 50, 17) $input2=GUICtrlCreateInput("", 208, 160, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Button3 = GUICtrlCreateButton("OK", 160, 232, 169, 41, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button3 $check=_CheckUsername($file,GUICtrlRead($input1)) If Not $check Then IniWrite($file, "UserData", GUICtrlRead($input1), GUICtrlRead($input2)) Else MsgBox(0, "", "Username already exists!") EndIf ExitLoop EndSwitch WEnd GUIDelete($Form1) EndFunc Func Signin() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 460, 293, 193, 125) $Group1 = GUICtrlCreateGroup("Register", 0, 0, 457, 289) $Label1 = GUICtrlCreateLabel("Enter Registration Information", 40, 48, 143, 17) $input1=GUICtrlCreateInput("", 208, 104, 233, 21) $Label2 = GUICtrlCreateLabel("Username", 48, 104, 52, 17) $Label3 = GUICtrlCreateLabel("Password", 48, 160, 50, 17) $input2=GUICtrlCreateInput("", 208, 160, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Button4 = GUICtrlCreateButton("OK", 160, 232, 169, 41, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button4 $check = _CheckUsername($file, GUICtrlRead($input1)) If $check Then $password = IniRead($file, "UserData", GUICtrlRead($input1), "") If Not @error And $password == GUICtrlRead($input2) Then MsgBox(0, "", "Credentials correct!") Exit ElseIf $password<>GUICtrlRead($input2) Then MsgBox (0, "", "Incorect Password Entered!") EndIf Else MsgBox(0,"","Incorrect Username Entered") EndIf ExitLoop EndSwitch WEnd GUIDelete($Form1) EndFunc Func _CheckUsername($file, $username) $var = IniReadSection($file, "UserData") If @error Then Return 0 Else For $i = 1 To $var[0][0] If $var[$i][0]=$username Then Return 1 Next Return 0 EndIf EndFunc;==>_CheckUsername Edited February 13, 2009 by Manjish [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Spiff59 Posted February 13, 2009 Share Posted February 13, 2009 It looks pretty good to me, I might have done a couple inor things alittle different, but that really amounts to personal preference, rather than something regarding good structure or concise code. I might suggest though.... putting a DISABLE state on the main GUI when the other two are launched, then back to ENABLE once they finish. Stop the user from closing the main window when theyre supposed to be working in a sub GUI. Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Author Share Posted February 13, 2009 I might suggest though.... putting a DISABLE state on the main GUI when the other two are launched, then back to ENABLE once they finish. Stop the user from closing the main window when theyre supposed to be working in a sub GUI. like this?? While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 GUISetState(@sw_disable) Register() GUISetState(@SW_ENABLE) Case $Button2 GUISetState(@sw_disable) Signin() GUISetState(@SW_ENABLE) EndSwitch WEnd [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Spiff59 Posted February 13, 2009 Share Posted February 13, 2009 Pardon my typos, my gal was rushing me out the door for work and I wasn't sure what I'd typed when I hit "Add Reply". That's what I was thinking. Since your main GUI is the active (and only existing) GUI at the time you execute those commands, I guess you don't need to qualify the GUISetState with the target hWnd. And I guess, you'll never be referening those called GUI's, so Koda naming them identically is no biggie. Just a personal thing, but I like visually knowing how many levels deep in a program I am, I think making popup windows smaller than the main window gives the user a better logical sense of "where they are" in the application. Anyway, looks nice, let us see what you end up with! Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Author Share Posted February 13, 2009 Just a personal thing, but I like visually knowing how many levels deep in a program I am, I think making popup windows smaller than the main window gives the user a better logical sense of "where they are" in the application. Hmm.. I agree, here.. Incorporated this 1 too.. expandcollapse popup#include <EditConstants.au3> #include <GUIConstants.au3> $file = "db.ini" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 436, 221, 193, 125) $Group1 = GUICtrlCreateGroup("Make A Choice", 0, 0, 433, 217) $Button1 = GUICtrlCreateButton("Register", 24, 152, 169, 33, 0) $Button2 = GUICtrlCreateButton("Login", 240, 152, 169, 33, 0) $Label1 = GUICtrlCreateLabel("What Do You Wish To Do?", 136, 72, 135, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 GUISetState(@sw_disable) Register() GUISetState(@SW_ENABLE) Case $Button2 GUISetState(@sw_disable) Signin() GUISetState(@sw_enable) EndSwitch WEnd Exit Func Register() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 350, 160, 193, 125) $Group1 = GUICtrlCreateGroup("Register", 0, 0, 345, 155) $Label1 = GUICtrlCreateLabel("Enter Registration Information", 40, 30, 143, 17) $input1=GUICtrlCreateInput("", 110, 70, 233, 21) $Label2 = GUICtrlCreateLabel("Username", 48, 70, 60, 17) $Label3 = GUICtrlCreateLabel("Password", 48, 120, 60, 17) $input2=GUICtrlCreateInput("", 110, 120, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Button3 = GUICtrlCreateButton("OK", 160, 232, 169, 41, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button3 $check=_CheckUsername($file,GUICtrlRead($input1)) If Not $check Then IniWrite($file, "UserData", GUICtrlRead($input1), GUICtrlRead($input2)) Else MsgBox(0, "", "Username already exists!") EndIf ExitLoop EndSwitch WEnd GUIDelete($Form1) EndFunc Func Signin() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 350, 160, 193, 125) $Group1 = GUICtrlCreateGroup("Register", 0, 0, 345, 155) $Label1 = GUICtrlCreateLabel("Enter Registration Information", 40, 30, 143, 17) $input1=GUICtrlCreateInput("", 110, 70, 233, 21) $Label2 = GUICtrlCreateLabel("Username", 48, 70, 60, 17) $Label3 = GUICtrlCreateLabel("Password", 48, 120, 60, 17) $input2=GUICtrlCreateInput("", 110, 120, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Button4 = GUICtrlCreateButton("OK", 160, 232, 169, 41, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button4 $check = _CheckUsername($file, GUICtrlRead($input1)) If $check Then $password = IniRead($file, "UserData", GUICtrlRead($input1), "") If Not @error And $password == GUICtrlRead($input2) Then MsgBox(0, "", "Credentials correct!") Exit ElseIf $password<>GUICtrlRead($input2) Then MsgBox (0, "", "Incorect Password Entered!") EndIf Else MsgBox(0,"","Incorrect Username Entered") EndIf ExitLoop EndSwitch WEnd GUIDelete($Form1) EndFunc Func _CheckUsername($file, $username) $var = IniReadSection($file, "UserData") If @error Then Return 0 Else For $i = 1 To $var[0][0] If $var[$i][0]=$username Then Return 1 Next Return 0 EndIf EndFunc;==>_CheckUsername [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 13, 2009 Moderators Share Posted February 13, 2009 Manjish,There are good encryption threads here and here. My personal favourite is this which is written in assembler (I used to really enjoy coding in that, not!) and is very fast. I use it a lot - but not for encryption.I have found it very handy to use when listing files in an index from which I wish to choose at random. Because it is so fast, producing an MD5 hash of the file path and name is no real penalty and I end up with an index containing a 32-character hash for each file, regardless of how long the path actually is. I add a "#" mark to the hash when the file is accessed - a simple StringLen then gives me the answer to "has it been accessed before?". If changes are made to the indexed folder (adding, deleting or renaming files) it is a trivial matter to make up a new index and then run through the 2 indexes comparing hashes and transposing the "#" where required. No horrible PathSplit or RegEx coding needed!M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Author Share Posted February 13, 2009 Melba23.. thanks for the pointers.. Here is the script including the encryption for the passwords.. Please see this.. Spiff56.. Anything else you can suggest for making this better?? Or is this it... please tell me if I am missing anything.. expandcollapse popup#include <EditConstants.au3> #include <GUIConstants.au3> #include<AES.au3> $file = "db.ini" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 436, 221, 193, 125) $Group1 = GUICtrlCreateGroup("Make A Choice", 0, 0, 433, 217) $Button1 = GUICtrlCreateButton("Register", 24, 152, 169, 33, 0) $Button2 = GUICtrlCreateButton("Login", 240, 152, 169, 33, 0) $Label1 = GUICtrlCreateLabel("What Do You Wish To Do?", 136, 72, 135, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 ;GUISetState(@sw_disable) Register() ;GUISetState(@SW_ENABLE) Case $Button2 ;GUISetState(@sw_disable) Signin() ;GUISetState(@sw_enable) EndSwitch WEnd Exit Func Register() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Register", 350, 200, 193, 125) $Group1 = GUICtrlCreateGroup("Register", 0, 0, 345, 195) $Label1 = GUICtrlCreateLabel("Enter Registration Information", 40, 30, 143, 17) $input1=GUICtrlCreateInput("", 110, 70, 233, 21) $Label2 = GUICtrlCreateLabel("Username", 48, 70, 60, 17) $Label3 = GUICtrlCreateLabel("Password", 48, 120, 60, 17) $input2=GUICtrlCreateInput("", 110, 120, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Button3 = GUICtrlCreateButton("OK", 90, 150, 169, 30, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button3 $check=_CheckUsername($file,GUICtrlRead($input1)) If Not $check Then IniWrite($file, "UserData", GUICtrlRead($input1), _AesEncrypt("Key",GUICtrlRead($input2))) Else MsgBox(0, "", "Username already exists!") EndIf ExitLoop EndSwitch WEnd GUIDelete($Form1) EndFunc Func Signin() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Login", 350, 200, 193, 125) $Group1 = GUICtrlCreateGroup("Login", 0, 0, 345, 195) $Label1 = GUICtrlCreateLabel("Enter Registration Information", 40, 30, 143, 17) $input1=GUICtrlCreateInput("", 110, 70, 233, 21) $Label2 = GUICtrlCreateLabel("Username", 48, 70, 60, 17) $Label3 = GUICtrlCreateLabel("Password", 48, 120, 60, 17) $input2=GUICtrlCreateInput("", 110, 120, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Button4 = GUICtrlCreateButton("OK", 90, 150, 169, 30, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button4 $check = _CheckUsername($file, GUICtrlRead($input1)) If $check Then $password = IniRead($file, "UserData", GUICtrlRead($input1), "") If Not @error And BinaryToString(_AesDecrypt("Key",$password)) == GUICtrlRead($input2) Then MsgBox(0, "", "Credentials correct!") Exit ElseIf BinaryToString(_AesDecrypt("Key",$password))<>GUICtrlRead($input2) Then MsgBox (0, "", "Incorect Password Entered!") EndIf Else MsgBox(0,"","Incorrect Username Entered") EndIf ExitLoop EndSwitch WEnd GUIDelete($Form1) EndFunc Func _CheckUsername($file, $username) $var = IniReadSection($file, "UserData") If @error Then Return 0 Else For $i = 1 To $var[0][0] If $var[$i][0]=$username Then Return 1 Next Return 0 EndIf EndFunc;==>_CheckUsername ; To encrypt/decrypt memory block or string: $Encrypted = _AesEncrypt("Key", "Plantext") $Decrypted = _AesDecrypt("Key", $Encrypted) $Result = BinaryToString($Decrypted) [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Manjish Posted February 14, 2009 Author Share Posted February 14, 2009 guys any other comments/suggestions? or is this fine enuf?? [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2009 Moderators Share Posted February 14, 2009 Manjish, If you are looking for work..... ;-) How about the user entering a duplicate password as a check when they register ? Most big sites ask for that. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Manjish Posted February 14, 2009 Author Share Posted February 14, 2009 sure.. that won't be much difficult to do.. just like usercheck function.. will do that.. thanks.. Got anything else? [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Metigue Posted February 14, 2009 Share Posted February 14, 2009 sure.. that won't be much difficult to do.. just like usercheck function.. will do that.. thanks.. Got anything else? Since the password is now saved encrypted, and users might not trust the program and use an unfamiliar password they are more likely to forget it, you could include a simple recovery question that the user writes and awnsers when registering. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now