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

Source for file Common.php

Documentation is available at Common.php

  1. <?php
  2. // LiveUser: A framework for authentication and authorization in PHP applications
  3. // Copyright (C) 2002-2003 Markus Wolff
  4. //
  5. // This library is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU Lesser General Public
  7. // License as published by the Free Software Foundation; either
  8. // version 2.1 of the License, or (at your option) any later version.
  9. //
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. // Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public
  16. // License along with this library; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19. /**
  20.  * Base class for authentication backends.
  21.  *
  22.  * @author   Lukas Smith <smith@backendmedia.com>
  23.  * @version  $Id: Common.php,v 1.23 2004/06/21 20:21:24 lsmith Exp $
  24.  * @package  LiveUser
  25.  * @category authentication
  26.  */
  27. {
  28.     /**
  29.      * Indicates if backend module initialized correctly. If yes,
  30.      * true, if not false. Backend module won't initialize if the
  31.      * init value (usually an object or resource handle that
  32.      * identifies the backend to be used) is not of the required
  33.      * type.
  34.      *
  35.      * @access public
  36.      * @var    boolean 
  37.      */
  38.     var $init_ok = false;
  39.  
  40.     /**
  41.      * Set posible encryption modes.
  42.      *
  43.      * @access private
  44.      * @var    array 
  45.      */
  46.     var $encryptionModes = array('MD5'   => 'MD5',
  47.                                  'RC4'   => 'RC4',
  48.                                  'PLAIN' => 'PLAIN',
  49.                                  'SHA1'  => 'SHA1');
  50.  
  51.     /**
  52.      * Defines the algorithm used for encrypting/decrypting
  53.      * passwords. Default: "MD5".
  54.      *
  55.      * @access private
  56.      * @var    string 
  57.      */
  58.     var $passwordEncryptionMode 'MD5';
  59.  
  60.  
  61.     /**
  62.      * The name associated with this auth container. The name is used
  63.      * when adding users from this container to the reference table
  64.      * in the permission container. This way it is possible to see
  65.      * from which auth container the user data is coming from.
  66.      *
  67.      * @var    string 
  68.      * @access public
  69.      */
  70.     var $name = null;
  71.  
  72.     /**
  73.      * Class constructor. Feel free to override in backend subclasses.
  74.      *
  75.      * @access protected
  76.      */
  77.     function LiveUser_Admin_Auth_Common(&$connectOptions$name = null)
  78.     {
  79.         if (is_array($connectOptions)) {
  80.             foreach ($connectOptions as $key => $value{
  81.                 if (isset($this->$key)) {
  82.                     $this->$key $value;
  83.                 }
  84.             }
  85.         }
  86.         if (!is_null($name)) {
  87.             $this->name = $name;
  88.         }
  89.     }
  90.  
  91.     /**
  92.      * Decrypts a password so that it can be compared with the user
  93.      * input. Uses the algorithm defined in the passwordEncryptionMode
  94.      * property.
  95.      *
  96.      * @access public
  97.      * @param  string password as an encrypted string
  98.      * @return string The decrypted password
  99.      */
  100.     function decryptPW($encryptedPW)
  101.     {
  102.         $decryptedPW 'Encryption type not supported.';
  103.  
  104.         switch (strtoupper($this->passwordEncryptionMode)) {
  105.             case 'PLAIN':
  106.                 $decryptedPW $encryptedPW;
  107.                 break;
  108.             case 'MD5':
  109.                 // MD5 can't be decoded, so return the string unmodified
  110.                 $decryptedPW $encryptedPW;
  111.                 break;
  112.             case 'RC4':
  113.                 $rc4 =LiveUser::CryptRC4Factory($this->_options['cookie']['secret']);
  114.                 if (LiveUser::isError($rc4)) {
  115.                     $this->_error $rc4;
  116.                     return $this->_error;
  117.                 }
  118.                 $this->rc4 =$rc4;
  119.                 $decryptedPW $encryptedPW;
  120.                 $this->rc4->decrypt($decryptedPW);
  121.                 break;
  122.             case 'SHA1':
  123.                 // SHA1 can't be decoded, so return the string unmodified
  124.                 $decryptedPW $encryptedPW;
  125.                 break;
  126.         }
  127.  
  128.         return $decryptedPW;
  129.     }
  130.  
  131.     /**
  132.      * Encrypts a password for storage in a backend container.
  133.      * Uses the algorithm defined in the passwordEncryptionMode
  134.      * property.
  135.      *
  136.      * @access public
  137.      * @param string  password as plain text
  138.      * @return string The encrypted password
  139.      */
  140.     function encryptPW($plainPW)
  141.     {
  142.         $encryptedPW 'Encryption type not supported.';
  143.  
  144.         switch (strtoupper($this->passwordEncryptionMode)) {
  145.             case 'PLAIN':
  146.                 $encryptedPW $plainPW;
  147.                 break;
  148.             case 'MD5':
  149.                 $encryptedPW md5($plainPW);
  150.                 break;
  151.             case 'RC4':
  152.                 if (!is_object($this->rc4)) {
  153.                     $rc4 =LiveUser::CryptRC4Factory($this->_options['cookie']['secret']);
  154.                     if (LiveUser::isError($rc4)) {
  155.                         $this->_error $rc4;
  156.                         return $this->_error;
  157.                     }
  158.                     $this->rc4 =$rc4;
  159.                 }
  160.                 $encryptedPW $plainPW;
  161.                 $this->rc4->crypt($encryptedPW);
  162.                 break;
  163.             case 'SHA1':
  164.                 if (!function_exists('sha1')) {
  165.                     return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  166.                         'SHA1 function doesn\'t exist. Upgrade your PHP version.');
  167.                 }
  168.                 $encryptedPW sha1($plainPW);
  169.                 break;
  170.         }
  171.  
  172.         return $encryptedPW;
  173.     }
  174.  
  175.     /**
  176.      * Function returns the inquired value if it exists in the class.
  177.      *
  178.      * @access public
  179.      * @param  string   Name of the property to be returned.
  180.      * @return mixed    null, a value or an array.
  181.      */
  182.     function getProperty($what)
  183.     {
  184.         $that = null;
  185.         if (isset($this->$what)) {
  186.             $that $this->$what;
  187.         }
  188.         return $that;
  189.     }
  190.  
  191.     /**
  192.      * Adds a new user to Auth.
  193.      *
  194.      * @access  public
  195.      * @param   string   Handle (username).
  196.      * @param   string   Password (optional).
  197.      * @param   boolean  Sets the user active (1) or not (0) (optional).
  198.      * @param   mixed    If specificed no new ID will be automatically generated instead
  199.      * @param   integer ID of the owning user.
  200.      * @param   integer ID of the owning group.
  201.      * @param   mixed   If specificed no new ID will be automatically generated instead
  202.      * @param   array   Array of custom fields to be added
  203.      * @return  mixed    Users auth ID on success, PEAR error if not.
  204.      */
  205.     function addUser($handle$password ''$active = true$owner_user_id = null,
  206.                     $owner_group_id = null$authId = null$customFields = array())
  207.     {
  208.         return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  209.             'addUser(): Method not supported by this container');
  210.     }
  211.  
  212.     /**
  213.      * Removes an existing user from Auth.
  214.      *
  215.      * @access  public
  216.      * @param   string   Auth user ID of the user that should be removed.
  217.      * @return  mixed    True on success, error object if not.
  218.      */
  219.     function removeUser($authId)
  220.     {
  221.         return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  222.             'removeUser(): Method not supported by this container');
  223.     }
  224.  
  225.     /**
  226.      * Changes user data in auth table.
  227.      *
  228.      * @access  public
  229.      * @param   string   Auth user ID.
  230.      * @param   string   Handle (username) (optional).
  231.      * @param   string   Password (optional).
  232.      * @param   boolean  Sets the user active (1) or not (0) (optional).
  233.      * @param   integer  ID of the owning user.
  234.      * @param   integer  ID of the owning group.
  235.      * @param   array   Array of custom fields to be updated.
  236.      * @return  mixed    True on success, error object if not.
  237.      */
  238.     function updateUser($authId$handle ''$password ''$active = null,
  239.                 $owner_user_id = null$owner_group_id = null$customFields = array())
  240.     {
  241.         return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  242.             'updateUser(): Method not supported by this container');
  243.     }
  244.  
  245.     /**
  246.      * Gets all users with handle, passwd, authId,
  247.      * lastlogin, is_active and individual rights.
  248.      *
  249.      * The array will look like this:
  250.      * <code>
  251.      * $userData[0]['auth_user_id']       = 'wujha433gawefawfwfiuj2ou9823r98h';
  252.      *             ['handle']       = 'myLogin';
  253.      *             ['passwd']     = 'd346gs2gwaeiuhaeiuuweijfjuwaefhj';
  254.      *             ['lastlogin']    = 1254801292; (Unix timestamp)
  255.      *             ['is_active']     = 1; (1 = yes, 0 = no)
  256.      * </code>
  257.      *
  258.      * @access  public
  259.      * @param   array  filters to apply to fetched data
  260.      * @param   array  custom fields you wane to be returned
  261.      * @return  mixed  Array with user data or error object.
  262.      */
  263.     function getUsers($filters = array()$customFields = array())
  264.     {
  265.         return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  266.             'getUsers(): Method not supported by this container');
  267.     }
  268. }

Documentation generated on Mon, 11 Mar 2019 13:56:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.