Home » Authentication » LiveUser » Bug #8212
Problem with PDO
Details
| Submitted | 2006-07-13 20:39 UTC |
|---|---|
| From | xerrez at worldofcrime dot de |
| Assigned | lsmith |
| Status | Closed |
| Package | LiveUser |
| PHP Version | 5.1.4 |
| OS | Debian 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;
}