Alright, for all intensive purposes this should work but it's not working at all...
I have a flat file that simply contains usernames and passwords separated by the | character. Here's a few lines of it:
bfellor|fb5f5ac46aa3a11582474df643b9db05
jkayman|b59f8f3854abf10b87093d912a936377
The password file is located out of the document root for security reasons, but there is no problem accessing it.
Here is my script to authenticate logins:
<?php
if($_POST['login']) {
$password = md5($_POST['pass_word']);
$handle = fopen("../passlist","r+b");
$string = fread($handle,filesize("../passlist"));
$lines = explode("\n",$string);
for($i = 0; $i < count($lines); $i++) {
$pass_array = explode("|",$lines[$i]);
echo $pass_array[0]."<br>\n";
echo $_POST['user_name']."<br>\n";
echo $pass_array[1]."<br>\n";
echo $password."<br>\n";
if(($pass_array[0] == $_POST['user_name']) && ($pass_array[1] == $password)) {
$logged_in = true;
}
}
if($logged_in) {
echo "<div class=\"item\">
<h2>Administration Page</h2>You're logged in!
</div>
</div>";
} else {
echo "<div class=\"item\">
<h2>Administration Page</h2>Sorry, we couldn't validate your credentials.<br>
Try again <a href=\"?page=login\">here</a>
</div>
</div>";
}
fclose($handle);
}
?>
The above script to my knowledge should work, but every time it comes up with "Sorry, we couldn't validate your credentials... etc.".
As you can see, I echoed out the usernames and passwords from the flatfile and the form and they're exactly the same, so I have no idea why the if structure isn't working right.
I'm at my wits end, heh.
Any help is appreciated. I'm sure it's something small that I'm overlooking. 🙂