protected function find_user()
{
// Get the user from the session
$user = $this->session()->get($this->_config['session']['key']);
// User found in session, return
if (is_object($user)) {
if ($user->loaded()) {
return $user;
} else {
// reloading failed - user is deleted but still exists in session
// logout (so session & cookie are cleared)
$this->logout(TRUE);
return FALSE;
}
}
if ($this->_config['cookie']['lifetime']) {
if ($token = Cookie::get($this->_config['cookie']['key'])) {
list($hash, $username) = explode('.', $token, 2);
if (strlen($hash) === 32 and $username !== NULL) {
// load user using username
$user = $this->_load_user($username);
// validates token vs hash
if ($user->loaded() and $this->check($hash, $user->{$this->_config['columns']['token']})) {
return $this->complete_login($user, TRUE);
}
}
}
}
return FALSE;
}