PDA

View Full Version : username/password problem


makexitxcount
08-03-2006, 09:25 AM
I´m trying to do a username/password verification, but it´s not working, even when the user/pass is correct, it will ask for the pass three times and then deny me the acces to the page, does somebody know what i´m doing wrong
the passwords.txt has the following format: username|password and here´s the code
<?php
if (!isset($PHP_AUTH_USER)) {
header('WWW-Authenticate: Basic realm="Acceso restringido"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}

$fich = file("passwords.txt");
$i=0; $validated=false;
while ($fich[$i] && !$validated) {
$field = explode("|",$fich[$i]);
if (($PHP_AUTH_USER==$field[0]) && ($PHP_AUTH_PW==chop($field[1]))) $validated=true;
$i++;
}

if (!$validated) {
header('WWW-Authenticate: Basic realm="Acceso restringido"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
?>
<html>
<head>
<title>Restricted Area</title>
</head>
<body>
Acces granted to the <B>restricted area</B> w/ username <?php echo $PHP_AUTH_USER?>.
</body>
</html>

makexitxcount
08-03-2006, 02:47 PM
up:thumbsup:

Fumigator
08-03-2006, 03:57 PM
If I were you I would add echo statements all over the place to see if the data coming out of the file and from the user input is the data I expect it to be.