I'm having trouble getting my login login to actually validate the user and log me in. I am able to open the text file that holds the users and passwords, but they never validate and I can't figure out why.
This is the code the calls the validation function:
/* Password login validation */
if ($authenticate == 0) {
// this will happen if authentication is turned off
$_SESSION['AUTH'] = 1;
$_SESSION['USER'] = 'default';
}
else {
ini_set('session.use_cookies', FALSE);
ini_set('session.use_trans_sid', FALSE);
session_start();
if ($login) {
$tmparray=VerifyPwd($user,$password);
if($tmparray["AUTH"]==0) {
unset($_SESSION["USER"]);
unset($_SESSION["HOME"]);
unset($_SESSION["AUTH"]);
// $msg = "Authentication Failed: Either your username or password are incorrect. Check your credentials and try again.";
$msg = "Authentication Failed: $user or $password are invalid. Check your credentials and try again.";
}
else {
$_SESSION["AUTH"] = $tmparray["AUTH"];
$_SESSION["USER"] = $tmparray["USER"];
$_SESSION["HOME"] = $tmparray["HOME"];
$_SESSION["TIME"] = time();
$navbar .= "<font face=verdana size=1> | <a href=\"$PHP_SELF\" name=\"logoff\">Logout</a></font>";
}
}
}
This is the actual login function:
function VerifyPwd($user,$password) {
global $data_file;
$found=false;
$ret = array();
$pwdcrypted=md5($password);
if (($fileopen = file($data_file)) == false) {
echo "File Open Error: Unable to read file $data_file";
}
while (list($linenum, $line) = each($fileopen) && !$found) {
$line=trim($line);
if(!preg_match("{^#}",$line) && $line!="") {
$array=explode("|",$line);
if($array[0]==$user && $array[1]==$pwdcrypted) {
$ret["AUTH"]=1;
$ret["USER"]=$user;
$ret["HOME"]=$array[2];
$found=true;
}
}
}
if(!$found) {
$ret["AUTH"]=0;
$ret["USER"]="";
$ret["HOME"]="";
}
return $ret;
}