PDA

View Full Version : Probs with AND operator!


Kixdemp
11-05-2005, 06:27 AM
Hello everyone! :D
Look at this code here:


# If this is the Chatbawx, and the username is the admin, and the password is incorrect,
if (($curUser[0] eq $uname) and ($curUser[1] eq $nickname) and ($curUser[2] ne $pass))
{
# Error
&error("Admin password supplied is invalid!<br>curUser[0] = $curUser[0]<br>uname = $uname<br>curUser[1] = $curUser[1]<br>nickname = $nickname<br>curUser[2] = $curUser[2]<br>pass = $pass");
}


That seems to always give me false. When I change the last "ne" to "eq", it always gives me true! Why is this? You can see that all of the info is correct:

---------------------
Error: Admin password supplied is invalid!
curUser[0] = sulfur
uname = sulfur
curUser[1] = sulfur
nickname = sulfur
curUser[2] = i0wnj00
pass = i0wnj00
---------------------

I tried chomping all the variables, plus all kinds of things, nothing works! HELP!
Thanks! ;)

nkrgupta
11-05-2005, 07:04 AM
With the data that you provide, the problem seems to be with the password part. Are you sure that the values assigned to $curUser[2] and $pass are as STRING? Or there are no leading or trailing whitespaces anywhere in the two variables?

Naveen

Kixdemp
11-05-2005, 07:42 AM
AHA! That's it! It had some stupid whitespaces! :mad:

$curUser[2] =~ s/\s*$//;
$pass =~ s/\s*$//;

That seemed to fix it... Thanks! :D

nkrgupta
11-05-2005, 07:52 AM
$curUser[2] =~ s/\s*$//;
$pass =~ s/\s*$//;


Alternative -

$curUser[2] =~ s/\s//g;
$pass =~ s/\s//g;


in case they are not at the end but *anywhere* else.

Kixdemp
11-05-2005, 09:05 AM
Thanks! I'll do that! ;)