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.21 2004/04/22 13:18:15 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.                 if (!is_object($this->rc4)) {
  114.                     @include_once 'Crypt/Rc4.php';
  115.                     if (!class_exists('Crypt_RC4')) {
  116.                         return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  117.                             'Please install Crypt_RC4 to use this feature');
  118.                     }
  119.                     $this->rc4 =new Crypt_RC4('LiveUserMagicKey');
  120.                 }
  121.                 $decryptedPW $encryptedPW;
  122.                 $this->rc4->decrypt($decryptedPW);
  123.                 break;
  124.             case 'SHA1':
  125.                 // SHA1 can't be decoded, so return the string unmodified
  126.                 $decryptedPW $encryptedPW;
  127.                 break;
  128.         }
  129.  
  130.         return $decryptedPW;
  131.     }
  132.  
  133.     /**
  134.      * Encrypts a password for storage in a backend container.
  135.      * Uses the algorithm defined in the passwordEncryptionMode
  136.      * property.
  137.      *
  138.      * @access public
  139.      * @param string  password as plain text
  140.      * @return string The encrypted password
  141.      */
  142.     function encryptPW($plainPW)
  143.     {
  144.         $encryptedPW 'Encryption type not supported.';
  145.  
  146.         switch (strtoupper($this->passwordEncryptionMode)) {
  147.             case 'PLAIN':
  148.                 $encryptedPW $plainPW;
  149.                 break;
  150.             case 'MD5':
  151.                 $encryptedPW md5($plainPW);
  152.                 break;
  153.             case 'RC4':
  154.                 if (!is_object($this->rc4)) {
  155.                     @include_once 'Crypt/Rc4.php';
  156.                     if (!class_exists('Crypt_RC4')) {
  157.                         return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  158.                             'Please install Crypt_RC4 to use this feature');
  159.                     }
  160.                     $this->rc4 =new Crypt_RC4('LiveUserMagicKey');
  161.                 }
  162.                 $encryptedPW $plainPW;
  163.                 $this->rc4->crypt($encryptedPW);
  164.                 break;
  165.             case 'SHA1':
  166.                 if (!function_exists('sha1')) {
  167.                     return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  168.                         'SHA1 function doesn\'t exist. Upgrade your PHP version.');
  169.                 }
  170.                 $encryptedPW sha1($plainPW);
  171.                 break;
  172.         }
  173.  
  174.         return $encryptedPW;
  175.     }
  176.  
  177.     /**
  178.      * Function returns the inquired value if it exists in the class.
  179.      *
  180.      * @access public
  181.      * @param  string   Name of the property to be returned.
  182.      * @return mixed    null, a value or an array.
  183.      */
  184.     function getProperty($what)
  185.     {
  186.         $that = null;
  187.         if (isset($this->$what)) {
  188.             $that $this->$what;
  189.         }
  190.         return $that;
  191.     }
  192.  
  193.     /**
  194.      * Adds a new user to Auth.
  195.      *
  196.      * @access  public
  197.      * @param   string   Handle (username).
  198.      * @param   string   Password (optional).
  199.      * @param   boolean  Sets the user active (1) or not (0) (optional).
  200.      * @param   mixed    If specificed no new ID will be automatically generated instead
  201.      * @param   integer ID of the owning user.
  202.      * @param   integer ID of the owning group.
  203.      * @param   mixed   If specificed no new ID will be automatically generated instead
  204.      * @param   array   Array of custom fields to be added
  205.      * @return  mixed    Users auth ID on success, PEAR error if not.
  206.      */
  207.     function addUser($handle$password ''$active = true$owner_user_id = null,
  208.                     $owner_group_id = null$authId = null$customFields = array())
  209.     {
  210.         return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  211.             'Method not supported by this container');
  212.     }
  213.  
  214.     /**
  215.      * Removes an existing user from Auth.
  216.      *
  217.      * @access  public
  218.      * @param   string   Auth user ID of the user that should be removed.
  219.      * @return  mixed    True on success, error object if not.
  220.      */
  221.     function removeUser($authId)
  222.     {
  223.         return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  224.             'Method not supported by this container');
  225.     }
  226.  
  227.     /**
  228.      * Changes user data in auth table.
  229.      *
  230.      * @access  public
  231.      * @param   string   Auth user ID.
  232.      * @param   string   Handle (username) (optional).
  233.      * @param   string   Password (optional).
  234.      * @param   boolean  Sets the user active (1) or not (0) (optional).
  235.      * @param   integer  ID of the owning user.
  236.      * @param   integer  ID of the owning group.
  237.      * @param   array   Array of custom fields to be updated.
  238.      * @return  mixed    True on success, error object if not.
  239.      */
  240.     function updateUser($authId$handle ''$password ''$active = null,
  241.                 $owner_user_id = null$owner_group_id = null$customFields = array())
  242.     {
  243.         return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  244.             'Method not supported by this container');
  245.     }
  246.  
  247.     /**
  248.      * Gets all users with handle, passwd, authId,
  249.      * lastlogin, is_active and individual rights.
  250.      *
  251.      * The array will look like this:
  252.      * <code>
  253.      * $userData[0]['auth_user_id']       = 'wujha433gawefawfwfiuj2ou9823r98h';
  254.      *             ['handle']       = 'myLogin';
  255.      *             ['passwd']     = 'd346gs2gwaeiuhaeiuuweijfjuwaefhj';
  256.      *             ['lastlogin']    = 1254801292; (Unix timestamp)
  257.      *             ['is_active']     = 1; (1 = yes, 0 = no)
  258.      * </code>
  259.      *
  260.      * @access  public
  261.      * @param   array  filters to apply to fetched data
  262.      * @param   array  custom fields you wane to be returned
  263.      * @return  mixed  Array with user data or error object.
  264.      */
  265.     function getUsers($filters = array()$customFields = array())
  266.     {
  267.         return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTEDnullnull,
  268.             'Method not supported by this container');
  269.     }
  270. }

Documentation generated on Mon, 11 Mar 2019 10:16:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.