PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Authentication » LiveUser » Bug #8212

Problem with PDO

Details

Submitted2006-07-13 20:39 UTC
Fromxerrez at worldofcrime dot de
Assignedlsmith
StatusClosed
PackageLiveUser
PHP Version5.1.4
OSDebian Etch
Roadmaps(Not assigned)

Comments

[2006-07-13 20:39 UTC] xerrez at worldofcrime dot de

Description:
------------
When using the PDO Auth Container no login is possible.
After receiving the row in the $row variable, there is a enquiry if the $result variable is an array. But this variable isn't set before, so it is not an error an the function readUserData return null.

(Sorry for my bad english. I am german)

Test script:
---------------
(original)
function readUserData($handle = '', $passwd = '', $auth_user_id = false)
{
$fields = array();
foreach ($this->tables['users']['fields'] as $field => $req) {
$fields[] = $this->alias[$field] . ' AS ' . $field;
}

// Setting the default query.
$query = 'SELECT ' . implode(',', $fields) . '
FROM ' . $this->prefix . $this->alias['users'] . '
WHERE ';
if ($auth_user_id) {
$query .= $this->alias['auth_user_id'] . '='
. $this->dbc->quote($auth_user_id);
} else {
$query .= $this->alias['handle'] . '='
. $this->dbc->quote($handle);

if (!is_null($this->tables['users']['fields']['passwd'])) {
// If $passwd is set, try to find the first user with the given
// handle and password.
$query .= ' AND ' . $this->alias['passwd'] . '='
. $this->dbc->quote($this->encryptPW($passwd));
}
}

// Query database
$res = $this->dbc->query($query);

if ($res === false) {
$error_info = $this->dbc->errorInfo();
$this->stack->push(
LIVEUSER_ERROR, 'exception',
array(
'reason' => $error_info[2],
'debug' => $query
)
);
return false;
}

$row = $res->fetch(PDO::FETCH_ASSOC);

if ($row === false) {
$this->stack->push(
LIVEUSER_ERROR, 'exception',
array(
'reason' => $this->dbc->errorCode(),
'debug' => $this->dbc->errorInfo()
)
);
return false;
}

if (!is_array($result)) {
return null;
}

// User was found, read data into class variables and set return value to true
if (array_key_exists('lastlogin', $row) && !empty($row['lastlogin'])) {
$row['lastlogin'] = strtotime($row['lastlogin']);
}
$this->propertyValues = $row;

return true;
}

(patched)
function readUserData($handle = '', $passwd = '', $auth_user_id = false)
{
$fields = array();
foreach ($this->tables['users']['fields'] as $field => $req) {
$fields[] = $this->alias[$field] . ' AS ' . $field;
}

// Setting the default query.
$query = 'SELECT ' . implode(',', $fields) . '
FROM ' . $this->prefix . $this->alias['users'] . '
WHERE ';
if ($auth_user_id) {
$query .= $this->alias['auth_user_id'] . '='
. $this->dbc->quote($auth_user_id);
} else {
$query .= $this->alias['handle'] . '='
. $this->dbc->quote($handle);

if (!is_null($this->tables['users']['fields']['passwd'])) {
// If $passwd is set, try to find the first user with the given
// handle and password.
$query .= ' AND ' . $this->alias['passwd'] . '='
. $this->dbc->quote($this->encryptPW($passwd));
}
}

// Query database
$res = $this->dbc->query($query);

if ($res === false) {
$error_info = $this->dbc->errorInfo();
$this->stack->push(
LIVEUSER_ERROR, 'exception',
array(
'reason' => $error_info[2],
'debug' => $query
)
);
return false;
}

$row = $res->fetch(PDO::FETCH_ASSOC);

if ($row === false) {
$this->stack->push(
LIVEUSER_ERROR, 'exception',
array(
'reason' => $this->dbc->errorCode(),
'debug' => $this->dbc->errorInfo()
)
);
return false;
}

if (!is_array($row)) {
return null;
}

// User was found, read data into class variables and set return value to true
if (array_key_exists('lastlogin', $row) && !empty($row['lastlogin'])) {
$row['lastlogin'] = strtotime($row['lastlogin']);
}
$this->propertyValues = $row;

return true;
}