Help - String comparisons are failing me?
Posted: Mon Dec 13, 2010 12:03 am
So, I'm a PHP newbie working on a basic account system.
I have one page with a password type input form. When I try to compare the pass to one I have in txt file, it fails. However, when I echo both the password and and the one I have on file, they both are identical... Help?
PS: file system works by basically creating a username.txt file for each user. second line of the file is their password.
I have one page with a password type input form. When I try to compare the pass to one I have in txt file, it fails. However, when I echo both the password and and the one I have on file, they both are identical... Help?
PS: file system works by basically creating a username.txt file for each user. second line of the file is their password.
Code: Select all
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$filelines = file($username.".txt");
if ($filelines === false) //checking for user existence
{
echo("Error: that username/password combination does not exist. (1)");
}
elseif ($password == $filelines[1]) //checking for pass/user combo consistency
{
echo("Login successful, welcome to PixelNations ".$username."! You will remain logged in for 30 mintues or until you choose to log out.<br>");
setcookie("loggedin", "1", time()+1800);
echo("<a href='blahblah/url.php'>CLICK HERE</a>");
}
else
{
echo("Error: that username/password combination does not exist. (2)");
echo("<br>pass = ".$password); //temporary, simply trying to get an idea of what's going on - except that they are identical! wtf?
echo("<br>file = ".$filelines[1]); //temporary ^
}
?>