PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Authentication » Auth » Bug #5846

Auth_Container_File broken when using Auth_HTTP

Details

Submitted2005-11-02 02:21 UTC
Fromahayes at wcg dot net dot au
Assignedaashley
StatusClosed
PackageAuth
PHP Version5.0.4
OSFedora Core 3
Roadmaps(Not assigned)

Comments

[2005-11-02 02:21 UTC] ahayes at wcg dot net dot au

Description:
------------
There seems to be a problem when using Auth_Container_File as a storage container with Auth_HTTP.

This is because Auth_HTTP expects to recieve an array of options, which will then create an instance of Auth_Container_File with that array of options, however Auth_Container_File has been created to recieve a string for the file name.

For instance, the Auth_Container_DB object recieves an array [1]

However, the Auth_Container_File treats its input as a string [2]

As far as I am aware this means it is not possible to use the HTTP_Auth package with the file storage container, however I could be wrong, in which case it would be nice to have an example in the documentation.

My solution to fix the problem is as in [3] and you would call it as in [4]

---------------------------------

[1] Auth/Container/DB.php line 67

function Auth_Container_DB($dsn) {
$this->_setDefaults();

if (is_array($dsn)) {
$this->_parseOptions($dsn);

if (empty($this->options['dsn'])) {
PEAR::raiseError('No connection parameters specified!');
}
} else {
$this->options['dsn'] = $dsn;
}
}

---------------------------------

[2] Auth/Container/File.php line 55

function Auth_Container_File($file)
{
$this->pwfile = $file;
}

---------------------------------

[3] Auth/Container/File.php line 55

function Auth_Container_File($file)
{
if(is_array($file)) {
$this->pwfile = $file['file'];
} else {
$this->pwfile = $file;
}
}

---------------------------------

[4] test-mod.php

<?php
// example of Auth_HTTP implementation with encrypted password and multiple columns fetch

require_once("Auth/HTTP.php");

// setting the database connection options
$AuthOptions = array(
'file' => './auth.passwd'
);

$a = new Auth_HTTP("File", $AuthOptions);

$a->setRealm('Blah'); // realm name
$a->setCancelText('<h2>Error 401</h2>'); // error message if authentication fails
$a->start(); // starting the authentication process

if($a->getAuth()) // checking for autenticated user
{
echo "Hello $a->username welcome to my secret page";
};

?>

Test script:
---------------
<?php
// example of Auth_HTTP implementation with encrypted password and multiple columns fetch

require_once("Auth/HTTP.php");

// setting the database connection options
$AuthOptions = './auth.passwd';

$a = new Auth_HTTP("File", $AuthOptions);

$a->setRealm('yourrealm'); // realm name
$a->setCancelText('<h2>Error 401</h2>'); // error message if authentication fails
$a->start(); // starting the authentication process

if($a->getAuth()) // checking for autenticated user
{
echo "Hello $a->username welcome to my secret page";

};

?>

Expected result:
----------------
Hello user welcome to my secret page

Actual result:
--------------
"Error 401"

Does not auth, as it will not find the file name.

[2006-02-21 05:03 UTC] aashley at php dot net

This bug has been fixed in CVS.

If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.