Source for file Common.php
Documentation is available at Common.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* A framework for authentication and authorization in PHP applications
* LiveUser is an authentication/permission framework designed
* to be flexible and easily extendable.
* Since it is impossible to have a
* "one size fits all" it takes a container
* approach which should enable it to
* be versatile enough to meet most needs.
* LICENSE: This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* @category authentication
* @author Markus Wolff <wolff@21st.de>
* @author Helgi Þormar Þorbjörnsson <dufuz@php.net>
* @author Lukas Smith <smith@pooteeweet.org>
* @author Arnaud Limbourg <arnaud@php.net>
* @author Pierre-Alain Joye <pajoye@php.net>
* @author Bjoern Kraus <krausbn@php.net>
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version CVS: $Id: Common.php,v 1.59 2006/08/15 06:43:20 mahono Exp $
* @link http://pear.php.net/LiveUser
* This class provides a set of functions for implementing a user
* authorisation system on live websites. All authorisation
* backends/containers must be inherited from this base class.
* @category authentication
* @author Markus Wolff <wolff@21st.de>
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version Release: @package_version@
* @link http://pear.php.net/LiveUser
* Has the current user successfully logged in?
* @see LiveUser_Auth_Common::isActive
* Timestamp of current login (last to be written)
* Auth maximum lifetime in seconds
* If this variable is set to 0, auth never expires
* Maximum time of idleness in seconds
* Idletime gets refreshed each time, init() is called. If this
* variable is set to 0, idle time is never checked.
* Possible encryption modes.
* Defines the algorithm used for encrypting/decrypting passwords.
* Defines the secret to use for encryption if needed
* Array of all the user data read from the backend database
* The name associated with this auth container. The name is used
* when adding users from this container to the reference table
* in the permission container. This way it is possible to see
* from which auth container the user data is coming from.
* External values to check (config settings)
* A list of handle fields that are used to find a user.
* All fields with their types
* All fields with their alias
* Class constructor. Feel free to override in backend subclasses.
* @var array configuration options
$this->stack = &PEAR_ErrorStack ::singleton ('LiveUser');
* Load the storage container
* @param array array containing the configuration.
* @param string name of the container that should be used
* @return bool true on success or false on failure
function init($conf, $containerName)
foreach ($keys as $key) {
if (isset ($this->$key)) {
$this->$key = & $conf[$key];
foreach ($keys as $key) {
if (isset ($this->$key)) {
$this->$key = & $conf['storage'][$key];
require_once 'LiveUser/Auth/Storage/Globals.php';
$this->tables = $GLOBALS['_LiveUser']['auth']['tables'];
$this->fields = $GLOBALS['_LiveUser']['auth']['fields'];
if (empty ($this->alias)) {
$this->alias = $GLOBALS['_LiveUser']['auth']['alias'];
* store all properties in an array
// get values from $this->externalValues['values'] and
// store them into $this->propertyValues['storedExternalValues']
* Reinitializes properties
* @param array $propertyValues
foreach ($propertyValues as $key => $value) {
return $this->externalValuesMatch ();
* Decrypts a password so that it can be compared with the user input.
* Uses the algorithm defined in the passwordEncryptionMode property.
* @param string the encrypted password
* @return string the decrypted password
* Encrypts a password for storage in a backend container.
* Uses the algorithm defined in the passwordEncryptionMode property.
* @param string encryption type
* @return string the encrypted password
* Tries to make a login with the given handle and password.
* A user can't login if he's not active.
* @param string user handle
* @param string user password
* @param bool|intif the user data should be read using the auth user id
* @return bool null when user is inactive, true on success or false on failure
function login($handle, $passwd, $auth_user_id = false )
// Init value: Is user logged in?
// Read user data from database
$result = $this->readUserData($handle, $passwd, $auth_user_id);
// If login is successful (user data has been read)
// ...we still need to check if this user is declared active
// ...and if so, we have a successful login (hooray)!
// In case Login was successful update user data
$this->_updateUserData ();
* Writes current values for user back to the database.
* This method does nothing in the base class and is supposed to
* be overridden in subclasses according to the supported backend.
* @return bool true on success or false on failure
function _updateUserData ()
array ('feature' => '_updateUserData')
* Reads user data from the given data source
* If only $handle is given, it will read the data
* from the first user with that handle and return
* If $handle and $passwd are given, it will try to
* find the first user with both handle and password
* matching and return true on success (this allows
* multiple users having the same handle but different
* passwords - yep, some people want this).
* if only an auth_user_id is passed it will try to read the data based on the id
* If no match is found, false is being returned.
* Again, this does nothing in the base class. The
* described functionality must be implemented in a
* subclass overriding this method.
* @param string user handle
* @param string user password
* @param bool|intif the user data should be read using the auth user id
* @return bool true on success or false on failure
function readUserData($handle = '', $passwd = '', $auth_user_id = false )
array ('feature' => 'readUserData')
* Function returns the inquired value if it exists in the class.
* @param string name of the property to be returned.
* @return mixed null, a scalar or an array.
} elseif (isset ($this->$what)) {
* Creates associative array of values from $externalValues['values'] with $keysToCheck
* Check if the stored external values match the current external values
* @return bool true on success or false on failure
foreach ($this->propertyValues['storedExternalValues'] as $keyToCheck => $storedValue) {
// return false if any one of the stored values does not match the current value
* properly disconnect from resources
* @return bool true on success or false on failure
Documentation generated on Mon, 28 Jan 2008 03:30:08 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|