Sign in to follow this  
Followers 0
laska

Comparison of strings

9 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

I have tried your suggestion but still getting MsgBox with username/password incorrect... Maybe any other suggestions? Thanks for efforts :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

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 :/

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Hahaha, so I forgot to read control of password input field :o Silly mistake, my bad :) Thanks for help, much appreciated :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0