Fix retrieving a user's data from the database

This commit is contained in:
Johannes Meyer 2014-11-04 13:03:12 +01:00
parent cad8f7538e
commit 99277383b9

View File

@ -81,13 +81,13 @@ class DbUserBackend extends UserBackend
* *
* @param string $username The name of the user to fetch * @param string $username The name of the user to fetch
* *
* @return array|null NULL in case the user does not exist * @return stdClass|null NULL in case the user does not exist
*/ */
public function getUser($username) public function getUser($username)
{ {
$select = new Zend_Db_Select($this->conn->getConnection()); $select = new Zend_Db_Select($this->conn->getConnection());
$row = $select->from('icingaweb_user')->where('name = ?', $username)->query()->fetch(); $row = $select->from('icingaweb_user')->where('name = ?', $username)->query()->fetchObject();
return empty($row) ? null : $row; return $row === false ? null : $row;
} }
/** /**
@ -104,12 +104,12 @@ class DbUserBackend extends UserBackend
{ {
try { try {
$userData = $this->getUser($user->getUsername()); $userData = $this->getUser($user->getUsername());
if ($userData === null || ! $userData['active']) { if ($userData === null || ! $userData->active) {
return false; return false;
} }
$hashToCompare = $this->hashPassword($password, $this->getSalt($userData['password_hash'])); $hashToCompare = $this->hashPassword($password, $this->getSalt($userData->password_hash));
return $hashToCompare === $userData['password_hash']; return $hashToCompare === $userData->password_hash;
} catch (Exception $e) { } catch (Exception $e) {
throw new AuthenticationException( throw new AuthenticationException(
'Failed to authenticate user "%s" against backend "%s". An exception was thrown:', 'Failed to authenticate user "%s" against backend "%s". An exception was thrown:',