public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$row = $this->database->table('users')->where('username', $username)->fetch();
if (!$row) {
throw new Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
} elseif (!Security\Passwords::verify($password, $row->password)) {
throw new Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
}
$arr = $row->toArray();
unset($arr['password']);
return new Security\Identity($row->id, NULL, $arr);
}