Page 1 of 1

if statement not working

Posted: Sat Oct 04, 2008 5:48 pm
by petethepirate
Im new to php5, and have been working on this for 3 days and cant figure out why its not working. Ok this is weird, I was editing the php file to post here and change $pass = $_POST["password"]; to $pass = $_POST["a"]; and it worked. I verified before and after the IF statement that both hashes did match. Can anyone see what Im doing wrong? Im new to php and dont quite have it figured out. Thanks. Heres the .php file.

<?php
ob_start();
session_start();
$pass = "a";
echo "<html>\n";
echo " <body>\n";
echo " <title>fix later</title>\n";
echo " </body>\n";;

$hpass = ("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");

$passwordHash = sha1($pass);

echo "<p>$hpass is hpass</p>\n";
echo "<p>$passwordHash is passwordHash</p>\n";

if ( $hpass == $passwordHash )
{
echo "<p>Welcome back $emailaddress</p>\n";
} else
{
echo "<p>Wrong password</p>\n";
}
echo "<p>$hpass is hpass</p>\n";
echo "<p>$passwordHash is passwordHash</p>\n";
?>

Re: if statement not working

Posted: Sat Oct 04, 2008 8:11 pm
by josh
you code does not reference the post data, you've hard coded an ascii character.

Re: if statement not working

Posted: Sat Oct 04, 2008 8:31 pm
by petethepirate
Yeah I did that so I didnt have to post 20 files.

Re: if statement not working

Posted: Sat Oct 04, 2008 9:07 pm
by josh
print_r( $_POST );

if you're going to edit your code before you post it, how are we gonna spot the bug? Obviously if changing it to "a" worked, then the field must be called "a" in the form or whatever is posting to your script