Source for file remember.php
Documentation is available at remember.php
* @subpackage System.remember
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Joomla! System Remember Me Plugin
* @subpackage System.remember
* @note Code improvements inspired by http://jaspan.com/improved_persistent_login_cookie_best_practice
* and http://fishbowl.pastiche.org/2004/01/19/persistent_login_cookie_best_practice/
* Whether to set as secure or not.
* Cookie lifetime in days.
* Length of random string.
* Constructor. We use it to set the app and db properties.
* @param object &$subject The object to observe
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'group', 'params', 'language'
* (this list is not meant to be comprehensive).
public function __construct(&$subject, $config =
array())
// Use domain and path set in config for cookie if it exists.
$this->secure =
$this->app->isSSLConnection();
* Remember me method to run onAfterInitialise
* @throws InvalidArgumentException
// No remember me for admin
if ($this->app->isAdmin())
$this->app->rememberCookieSecure =
$this->secure;
$this->app->rememberCookieLength =
$this->length;
if ($user->get('guest') ==
1)
// Create the cookie name and data
if ($rememberArray !==
false)
if (count($rememberArray) !=
3)
// Destroy the cookie in the browser.
$this->app->input->cookie->set(end($rememberArray), false, time() -
42000, $this->app->get('cookie_path'), $this->app->get('cookie_domain'));
JLog::add('Invalid cookie detected.', JLog::WARNING, 'error');
list
($privateKey, $series, $uastring) =
$rememberArray;
JLog::add('Error in deleting expired cookie tokens.', JLog::WARNING, 'error');
// Find the matching record if it exists
$query =
$this->db->getQuery(true)
->select($this->db->quoteName(array('user_id', 'token', 'series', 'time', 'invalid')))
->from($this->db->quoteName('#__user_keys'))
->where($this->db->quoteName('series') .
' = ' .
$this->db->quote(base64_encode($series)))
->where($this->db->quoteName('uastring') .
' = ' .
$this->db->quote($uastring))
->order($this->db->quoteName('time') .
' DESC');
$results =
$this->db->setQuery($query)->loadObjectList();
$countResults =
count($results);
// We have a user but a cookie that is not in the database, or it is invalid. This is a possible attack, so invalidate everything.
if (($countResults ===
0 ||
$results[0]->invalid !=
0) &&
!empty($results[0]->user_id))
JLog::add(JText::sprintf('PLG_SYSTEM_REMEMBER_ERROR_LOG_INVALIDATED_COOKIES', $user->username), JLog::WARNING, 'security');
// Possibly e-mail user and admin here.
// We have a user with one cookie with a valid series and a corresponding record in the database.
if (substr($results[0]->token, 0, 4) ===
'$2y$')
JLog::add(JText::sprintf('PLG_SYSTEM_REMEMBER_ERROR_LOG_LOGIN_FAILED', $user->username), JLog::WARNING, 'security');
// Set up the credentials array to pass to onUserAuthenticate
'username' =>
$results[0]->user_id,
return $this->app->login($credentials, array('silent' =>
true, 'lifetime' =>
$this->lifetime, 'secure' =>
$this->secure, 'length' =>
$this->length));
Documentation generated on Tue, 19 Nov 2013 15:11:45 +0100 by phpDocumentor 1.4.3