/**
* Finds out if a username and password is valid.
*
* @param string $user The username to check.
* @param string $oldpass An old password to check.
*
* @throws Passwd_Exception
*/
protected function _lookup($user, $oldpass)
{
/* Only split up username if domain is set in backend configuration. */
if (!empty($this->_params['domain'])) {
list($name, $domain) = explode('@', $user);
} else {
$name = $user;
}
/* Build the SQL query. */
$sql = 'SELECT ' . $this->_params['passwd'] . ' FROM ' . $this->_params['table'] . ' WHERE ' . $this->_params['name'] . ' = ?';
$values = array($name);
if ($this->_params['domain']) {
$sql .= ' AND ' . $this->_params['domain'] . ' = ?';
$values[] = $domain;
}
/* Execute the query. */
try {
$result = $this->_db->selectOne($sql, $values);
} catch (Horde_Db_Exception $e) {
throw new Passwd_Exception($e);
}
if (!is_array($result)) {
throw new Passwd_Exception(_("User not found"));
}
/* Check the passwords match. */
$this->_comparePasswords($result[$this->_params['passwd']], $oldpass);
}