 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
geoffschultz
Joined: 26 Aug 2007 Posts: 3
|
Posted: Sun Aug 26, 2007 8:17 pm Post subject: Auth_ HTTP Won't Authenticate. addUser/changePassword works |
|
|
I've been trying to get this basic example working, but it won't authenticate. I enter test/test1 as the username/pw and I just keep getting the login window. addUser create users with no problems, changePassword works fine (as used below), and listUsers outputs a user list as expected. I can't figure out what's happening.
Here's a link to the following code: http://www.geoffschultz.org/Test/test2.php
Any suggestions would be greatly appreciated.
| Code: | require_once("Auth/HTTP.php");
require_once 'PEAR.php';
function handle_pear_error($e) {
die($e->getMessage() . ' ' . print_r($e->getUserInfo(), true));
}
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handle_pear_error');
// setting the database connection options
$AuthOptions = array(
'dsn'=>"mysql://user:pw@host/table",
'table'=> "sailor", // your table name
'usernamecol'=>"email", // the table username column
'passwordcol'=>"password", // the table password column
'cryptType'=>"none", // password encryption type in your db
);
$a = new Auth_HTTP("MDB2", $AuthOptions);
$a->changePassword("test","test1");
print_r ($a->listUsers());
$a->setRealm('Admin Area'); // realm name
$a->setCancelText('Login Failed!'); // error message if authentication fails
$a->start(); // starting the authentication process
if ($a->getAuth()) // checking for autenticated user
{
echo "Hello $a->username";
}; |
|
|
| Back to top |
|
 |
geoffschultz
Joined: 26 Aug 2007 Posts: 3
|
Posted: Mon Aug 27, 2007 12:41 pm Post subject: |
|
|
% pear list
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.2 stable
Auth 1.5.4 stable
Auth_HTTP 2.1.6 stable
Config 1.10.11 stable
Console_Getopt 1.2.3 stable
HTML_Template_IT 1.2.1 stable
Log 1.9.11 stable
MDB2 2.4.1 stable
MDB2_Driver_mysql 1.4.1 stable
MIME_Type 1.0.0 stable
PEAR 1.6.1 stable
PEAR_Frontend_Web 0.7.1 beta
Structures_Graph 1.0.2 stable
% |
|
| Back to top |
|
 |
geoffschultz
Joined: 26 Aug 2007 Posts: 3
|
Posted: Tue Aug 28, 2007 5:11 pm Post subject: |
|
|
To make things even stranger, I can use the non-HTTP version of Auth without any problems. If I run the auth_HTTP version after logging in via Auth, I get the "logged in" message. If I place a call to logout() in the HTTP version, I get the login dialog box, but I can't log in.
-- Geoff _________________ -- Geoff
http://www.GeoffSchultz.org |
|
| Back to top |
|
 |
BA
Joined: 31 Aug 2007 Posts: 2
|
Posted: Tue Oct 02, 2007 1:49 am Post subject: |
|
|
| geoffschultz wrote: | To make things even stranger, I can use the non-HTTP version of Auth without any problems. If I run the auth_HTTP version after logging in via Auth, I get the "logged in" message. If I place a call to logout() in the HTTP version, I get the login dialog box, but I can't log in.
-- Geoff |
Geoff, I have the *exact* same problem with version 1.5.4 of Auth (the latest release). Without a doubt there is a bug in the Auth package, and without a doubt the documentation is sorely lacking in substance. I've just spent hours trying to figure this one out (I LOVE wasting hours of my time debugging PEAR packages, which is getting to be a habit due to unimaginably poor documentation and virtually no validation of parameters passed into these PEAR objects which we're all consuming...)
The problem is that 'usernamecol' in the options array is, by default, looking for a field in your table called "username", and does NOT recognize the field name you specify IF you have defined the options array as shown here:
| Code: |
$Options = array('dsn' => $this->DSN,
'table' => "USER_DETAILS",
'usernamecol' => "EMAIL",
'passwordcol' => "PASSWORD",
'cryptType' => "",
'db_fields' => "*");
|
The bug that causes this misery is happening because there's an important parameter missing from the options array (which is not well documented so it's no wonder so many of us are having problems)...
In your options array, do this instead:
| Code: |
$Options = array('dsn' => $this->DSN,
'table' => "USER_DETAILS",
'usernamecol' => "EMAIL",
'passwordcol' => "PASSWORD",
'cryptType' => "",
'db_fields' => "*",
'db_options' => array('portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE)); |
...by specifying the 'db_options' as shown, the username column is correctly mapped to whatever field you specify in 'usernamecol', and it works...
I can't tell you how many websites I had to surf, and how many hours of trial and error I had to endure to figure this out.
To help debug your problem, you can make a call to the listUsers() method and see exactly what fields are being returned (all fields in your users table will be returned only IF you specify 'db_fields' => "*"). So try this out:
print_r($Auth->listUsers());
You should see something like this:
Array ( [0] => Array ( [id] => 1 [username] => [password] => BLAH [type_id] => [email] => test@test.com ) )
...this is the structure of my own users table. Notice how 'username' is blank. In my table I actually do NOT have a field called 'username'. Even if you do not have a field called 'username' in your users table, Auth for some bizarre reason, always expects it to be there. There is definitely a bug here. So you either have to specify the options array as I showed above, or you have to actually have a field called 'username' (in lower case) in your table. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|