laska Posted April 2, 2016 Share Posted April 2, 2016 Hello everyone! I'm new to the forum and I'm not quite sure if I'm posting in correct sub forum, sorry AutoIt is my first touch with scripting/programming. I started off something simple (I thought)... Simple gui: 2 inputs, 2 buttons. Script is a "Login Form", and my goal was to get MsgBox saying "Success" but I'm getting MsgBox with error in logging in... The syntax is correct (according to SyntaxCheck) and I could not figure out what is wrong :/ #include <EditConstants.au3> Opt("GUIOnEventMode", 1) Global $input_login, $input_pass, $btn_login, $btn_reg GUICreate("Login", 170, 80) GUICtrlCreateLabel("Login:", 5, 5, 50, 20) $input_login = GUICtrlCreateInput("", 60, 5, 100, 20) GUICtrlSetData($input_login, "") GUICtrlCreateLabel("Password:", 5, 30, 50, 20) $input_pass = GUICtrlCreateInput("", 60, 30, 100, 20, $ES_PASSWORD) GUICtrlSetData($input_pass, "") $btn_login = GUICtrlCreateButton("Login", 5, 55, 40, 20) GUICtrlSetOnEvent($btn_login, "Login") $btn_reg = GUICtrlCreateButton("Register", 50, 55, 60, 20) GUICtrlSetOnEvent($btn_reg, "Register") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func Login() If FileExists(".\usr\" & GUICtrlRead($input_login) & ".ini") And $input_pass == IniRead(".\usr\" & GUICtrlRead($input_login) & ".ini", "Data", "PW", "") Then MsgBox(0, "Login", "Success") Exit Else MsgBox(0, "Login", "The username or password was incorrect!") Exit EndIf EndFunc Can anyone please point out to me what am I doing wrong? :L Best regards, laska Link to comment Share on other sites More sharing options...
iamtheky Posted April 3, 2016 Share Posted April 3, 2016 (edited) So you have relative to your script, a usr directory, and within that an ini that has the password that is required? And you want it to return an empty string if that iniread fails to return the contents of the PW key? And you have a register function that requires us to comment that section out to test this. Those are all actual desired behaviors? Edited April 3, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
laska Posted April 3, 2016 Author Share Posted April 3, 2016 Yes. The idea is that the login is the name of ini file in that directory. I was not sure what i should put in case of fail of iniread. I have tested: Func Login() If FileExists(".\usr\" & GUICtrlRead($input_login) & ".ini") And $input_pass == IniRead(".\usr\" & GUICtrlRead($input_login) & ".ini", "Data", "PW", "") Then MsgBox(0, "Login", "Success") Exit Else MsgBox(0, "Login", IniRead(".\usr\" & GUICtrlRead($input_login) & ".ini", "Data", "PW", "")) Exit EndIf EndFunc And that returned the contents of PW key. From what I've tried, it seems that comparison $input_pass == IniRead() is not functioning correctly... The Register() function did not happen, due to not working Login() function. Thank you for quick reply Link to comment Share on other sites More sharing options...
iamtheky Posted April 3, 2016 Share Posted April 3, 2016 (edited) Awesome, then your only error is this: ".\usr\" & GUICtrlRead($input_login) & ".ini" should look like @ScriptDir & "\usr\" & GUICtrlRead($input_login) & ".ini" Or not as the following works with both syntax in play $input_login = "testuser" $input_pass = "testpass" Login() Func Login() msgbox(0, '' , IniRead(@ScriptDir & "\usr\" & $input_login & ".ini", "Data", "PW", "")) If FileExists(".\usr\" & $input_login & ".ini") And $input_pass == IniRead(".\usr\" & $input_login & ".ini", "Data", "PW", "") Then MsgBox(0, "Login", "Success") Exit Else MsgBox(0, "Login", IniRead(".\usr\" & GUICtrlRead($input_login) & ".ini", "Data", "PW", "")) Exit EndIf EndFunc with ini that looks like [Data] PW = testpass Edited April 3, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
laska Posted April 3, 2016 Author Share Posted April 3, 2016 I have tried your suggestion but still getting MsgBox with username/password incorrect... Maybe any other suggestions? Thanks for efforts Link to comment Share on other sites More sharing options...
iamtheky Posted April 3, 2016 Share Posted April 3, 2016 (edited) Work backwards from my functioning example. Post your ini. Msgbox everything in your function, that way you are absolutely sure about what is occuring, as i did with the initial iniread to verify that the value returned from the ini was the expected value. Edited April 3, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
laska Posted April 3, 2016 Author Share Posted April 3, 2016 test.ini [Data] PW=123 Your Login() works but with my gui #include <EditConstants.au3> Opt("GUIOnEventMode", 1) Global $input_login, $input_pass, $btn_login, $btn_reg GUICreate("Login", 170, 80) GUICtrlCreateLabel("Login:", 5, 5, 50, 20) $input_login = GUICtrlCreateInput("", 60, 5, 100, 20) GUICtrlSetData($input_login, "") GUICtrlCreateLabel("Password:", 5, 30, 50, 20) $input_pass = GUICtrlCreateInput("", 60, 30, 100, 20, $ES_PASSWORD) GUICtrlSetData($input_pass, "") $btn_login = GUICtrlCreateButton("Login", 5, 55, 40, 20) GUICtrlSetOnEvent($btn_login, "Login") $btn_reg = GUICtrlCreateButton("Register", 50, 55, 60, 20) GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func Login() msgbox(0, '' , IniRead(@ScriptDir & "\usr\" & $input_login & ".ini", "Data", "PW", "")) If FileExists(".\usr\" & $input_login & ".ini") And $input_pass == IniRead(".\usr\" & $input_login & ".ini", "Data", "PW", "") Then MsgBox(0, "Login", "Success") Exit Else MsgBox(0, "Login", IniRead(".\usr\" & GUICtrlRead($input_login) & ".ini", "Data", "PW", "")) Exit EndIf EndFunc it does not :/ Link to comment Share on other sites More sharing options...
iamtheky Posted April 3, 2016 Share Posted April 3, 2016 (edited) definitely you have to put the guictrlread back... And all apologies, the lack of GuiCtrlRead on your AND $input_pass was probably the culprit all along (I blame the NCAA Final Four) try: #include <EditConstants.au3> Opt("GUIOnEventMode", 1) Global $input_login, $input_pass, $btn_login, $btn_reg GUICreate("Login", 170, 80) GUICtrlCreateLabel("Login:", 5, 5, 50, 20) $input_login = GUICtrlCreateInput("", 60, 5, 100, 20) GUICtrlSetData($input_login, "") GUICtrlCreateLabel("Password:", 5, 30, 50, 20) $input_pass = GUICtrlCreateInput("", 60, 30, 100, 20, $ES_PASSWORD) GUICtrlSetData($input_pass, "") $btn_login = GUICtrlCreateButton("Login", 5, 55, 40, 20) GUICtrlSetOnEvent($btn_login, "Login") $btn_reg = GUICtrlCreateButton("Register", 50, 55, 60, 20) GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func Login() msgbox(0, '' , IniRead(@ScriptDir & "\usr\" & GUICtrlRead($input_login) & ".ini", "Data", "PW", "")) If FileExists(@ScriptDir & "\usr\" & GUICtrlRead($input_login) & ".ini") And GuiCtrlRead($input_pass) == IniRead(@ScriptDir & "\usr\" & GUICtrlRead($input_login) & ".ini", "Data", "PW", "") Then MsgBox(0, "Login", "Success") Exit Else MsgBox(0, "Login", IniRead(".\usr\" & GUICtrlRead($input_login) & ".ini", "Data", "PW", "")) Exit EndIf EndFunc Edited April 3, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
laska Posted April 3, 2016 Author Share Posted April 3, 2016 Hahaha, so I forgot to read control of password input field Silly mistake, my bad Thanks for help, much appreciated 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