LiveUser
[ class tree: LiveUser ] [ index: LiveUser ] [ all elements ]

Source for file PEARAuth.php

Documentation is available at PEARAuth.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * A framework for authentication and authorization in PHP applications
  6.  *
  7.  * LiveUser is an authentication/permission framework designed
  8.  * to be flexible and easily extendable.
  9.  *
  10.  * Since it is impossible to have a
  11.  * "one size fits all" it takes a container
  12.  * approach which should enable it to
  13.  * be versatile enough to meet most needs.
  14.  *
  15.  * PHP version 4 and 5
  16.  *
  17.  * LICENSE: This library is free software; you can redistribute it and/or
  18.  * modify it under the terms of the GNU Lesser General Public
  19.  * License as published by the Free Software Foundation; either
  20.  * version 2.1 of the License, or (at your option) any later version.
  21.  *
  22.  * This library is distributed in the hope that it will be useful,
  23.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  25.  * Lesser General Public License for more details.
  26.  *
  27.  * You should have received a copy of the GNU Lesser General Public
  28.  * License along with this library; if not, write to the Free Software
  29.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30.  * MA  02111-1307  USA
  31.  *
  32.  *
  33.  * @category authentication
  34.  * @package LiveUser
  35.  * @author  Markus Wolff <wolff@21st.de>
  36.  * @author  Helgi Þormar Þorbjörnsson <dufuz@php.net>
  37.  * @author  Lukas Smith <smith@pooteeweet.org>
  38.  * @author  Arnaud Limbourg <arnaud@php.net>
  39.  * @author  Pierre-Alain Joye <pajoye@php.net>
  40.  * @author  Bjoern Kraus <krausbn@php.net>
  41.  * @copyright 2002-2006 Markus Wolff
  42.  * @license http://www.gnu.org/licenses/lgpl.txt
  43.  * @version CVS: $Id: PEARAuth.php,v 1.39 2006/04/13 15:26:49 lsmith Exp $
  44.  * @link http://pear.php.net/LiveUser
  45.  */
  46.  
  47. /**
  48.  * Require parent class definition and PEAR::Auth class.
  49.  */
  50. require_once 'LiveUser/Auth/Common.php';
  51. require_once 'Auth.php';
  52.  
  53. /**
  54.  * PEAR_Auth container for Authentication
  55.  *
  56.  * This is a PEAR::Auth backend driver for the LiveUser class.
  57.  * The general options to setup the PEAR::Auth class can be passed to the constructor.
  58.  * To choose the right auth container and options, you have to set 'container'
  59.  * and 'options' respectively in the storage array.
  60.  *
  61.  * Requirements:
  62.  * - File "LiveUser.php" (contains the parent class "LiveUser")
  63.  * - PEAR::Auth must be installed in your PEAR directory
  64.  * - Array of setup options must be passed to the constructor.
  65.  *
  66.  * @category authentication
  67.  * @package LiveUser
  68.  * @author  Bjoern Kraus <krausbn@php.net>
  69.  * @copyright 2002-2006 Markus Wolff
  70.  * @license http://www.gnu.org/licenses/lgpl.txt
  71.  * @version Release: @package_version@
  72.  * @link http://pear.php.net/LiveUser
  73.  */
  74. {
  75.     /**
  76.      * Contains the PEAR::Auth object.
  77.      *
  78.      * @var    Auth 
  79.      * @access private
  80.      */
  81.     var $pearAuth = false;
  82.  
  83.     /**
  84.      * Contains name of the auth container
  85.      *
  86.      * @var    string 
  87.      * @access private
  88.      */
  89.     var $container = false;
  90.  
  91.     /**
  92.      * Contains array options
  93.      *
  94.      * @var    array 
  95.      * @access private
  96.      */
  97.     var $options = false;
  98.  
  99.     /**
  100.      * Load the storage container
  101.      *
  102.      * @param   array  array containing the configuration.
  103.      * @param string  name of the container that should be used
  104.      * @return bool true on success or false on failure
  105.      *
  106.      * @access public
  107.      */
  108.     function init(&$conf$containerName)
  109.     {
  110.         parent::init($conf$containerName);
  111.  
  112.         if (!is_a($this->pearAuth'auth'&& $this->container{
  113.             $pearAuth &new Auth($this->container$this->options''false);
  114.             if (PEAR::isError($pearAuth)) {
  115.                 $this->stack->push(LIVEUSER_ERROR_INIT_ERROR'error',
  116.                     array('container' => 'could not connect: '.$pearAuth->getMessage(),
  117.                     'debug' => $pearAuth->getUserInfo()));
  118.                 return false;
  119.             }
  120.             $this->pearAuth =$pearAuth;
  121.         }
  122.  
  123.         if (!is_a($this->pearAuth'auth')) {
  124.             $this->stack->push(LIVEUSER_ERROR_INIT_ERROR'error',
  125.                 array('container' => 'storage layer configuration missing'));
  126.             return false;
  127.         }
  128.  
  129.         return true;
  130.     }
  131.  
  132.     /**
  133.      * Does nothing
  134.      *
  135.      * @return bool true on success or false on failure
  136.      *
  137.      * @access private
  138.      */
  139.     function _updateUserData()
  140.     {
  141.         return true;
  142.     }
  143.  
  144.     /**
  145.      * Reads user data from the given data source
  146.      * Starts and verifies the PEAR::Auth login process
  147.      *
  148.      * @param  string user handle
  149.      * @param  string user password
  150.      * @param  bool|intif the user data should be read using the auth user id
  151.      * @return bool true on success or false on failure
  152.      *
  153.      * @access public
  154.      */
  155.     function readUserData($handle ''$passwd ''$auth_user_id = false)
  156.     {
  157.         $this->pearAuth->username = ($auth_user_id !== false$auth_user_id $handle;
  158.         $this->pearAuth->password = $passwd;
  159.         $this->pearAuth->start();
  160.  
  161.         if (!$this->pearAuth->getAuth()) {
  162.             return null;
  163.         }
  164.  
  165.         // User was found, read data into class variables and set return value to true
  166.         $this->propertyValues['auth_user_id'$this->pearAuth->getUsername();
  167.         $this->propertyValues['handle'$this->pearAuth->getUsername();
  168.         $this->propertyValues['passwd'$this->encryptPW($this->pearAuth->password);
  169.         if (!array_key_exists('is_active'$this->tables['users']['fields'])) {
  170.             $this->propertyValues['is_active'= true;
  171.         }
  172.         if (!array_key_exists('lastlogin'$this->tables['users']['fields'])) {
  173.             $this->propertyValues['lastlogin'= null;
  174.         }
  175.         return true;
  176.     }
  177. }
  178. ?>

Documentation generated on Mon, 28 Jan 2008 03:30:31 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.