Jump to content

username/password problem


makexitxcount

Recommended Posts

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
[code=php:0]<?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>[/code]
Link to comment
Share on other sites

I'm not familiar with PHP_AUTH_USER and how that gets set, but I have some suggestions that might help.

First of all, to find out where the problem is, you could add to echo 'Authorization Required'

.'user='.$PHP_AUTH_USER.', pw='.$PHP_AUTH_PW

the problem might be in the setting of these variables. 

if that's not it, perhaps the usernames in your password.txt file are preceded by spaces or other characters
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.