home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / php / PEAR / Auth / Container.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  6.4 KB  |  263 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
  3.  
  4. /**
  5.  * Auth_Container Base Class
  6.  *
  7.  * PHP versions 4 and 5
  8.  *
  9.  * LICENSE: This source file is subject to version 3.01 of the PHP license
  10.  * that is available through the world-wide-web at the following URI:
  11.  * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
  12.  * the PHP License and are unable to obtain it through the web, please
  13.  * send a note to license@php.net so we can mail you a copy immediately.
  14.  *
  15.  * @category   Authentication
  16.  * @package    Auth
  17.  * @author     Martin Jansen <mj@php.net>
  18.  * @author     Adam Ashley <aashley@php.net>
  19.  * @copyright  2001-2006 The PHP Group
  20.  * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
  21.  * @version    CVS: $Id: Container.php,v 1.27 2007/02/02 00:41:14 aashley Exp $
  22.  * @link       http://pear.php.net/package/Auth
  23.  */
  24.  
  25. /**
  26.  * Storage class for fetching login data
  27.  *
  28.  * @category   Authentication
  29.  * @package    Auth
  30.  * @author     Martin Jansen <mj@php.net>
  31.  * @author     Adam Ashley <aashley@php.net>
  32.  * @copyright  2001-2006 The PHP Group
  33.  * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
  34.  * @version    Release: 1.5.0  File: $Revision: 1.27 $
  35.  * @link       http://pear.php.net/package/Auth
  36.  */
  37. class Auth_Container
  38. {
  39.  
  40.     // {{{ properties
  41.  
  42.     /**
  43.      * User that is currently selected from the storage container.
  44.      *
  45.      * @access public
  46.      */
  47.     var $activeUser = "";
  48.  
  49.     /**
  50.      * The Auth object this container is attached to.
  51.      *
  52.      * @access public
  53.      */
  54.     var $_auth_obj = null;
  55.  
  56.     // }}}
  57.     // {{{ Auth_Container() [constructor]
  58.  
  59.     /**
  60.      * Constructor
  61.      *
  62.      * Has to be overwritten by each storage class
  63.      *
  64.      * @access public
  65.      */
  66.     function Auth_Container()
  67.     {
  68.     }
  69.  
  70.     // }}}
  71.     // {{{ fetchData()
  72.  
  73.     /**
  74.      * Fetch data from storage container
  75.      *
  76.      * Has to be overwritten by each storage class
  77.      *
  78.      * @access public
  79.      */
  80.     function fetchData($username, $password, $isChallengeResponse=false)
  81.     {
  82.         $this->log('Auth_Container::fetchData() called.', AUTH_LOG_DEBUG);
  83.     }
  84.  
  85.     // }}}
  86.     // {{{ verifyPassword()
  87.  
  88.     /**
  89.      * Crypt and verfiy the entered password
  90.      *
  91.      * @param  string Entered password
  92.      * @param  string Password from the data container (usually this password
  93.      *                is already encrypted.
  94.      * @param  string Type of algorithm with which the password from
  95.      *                the container has been crypted. (md5, crypt etc.)
  96.      *                Defaults to "md5".
  97.      * @return bool   True, if the passwords match
  98.      */
  99.     function verifyPassword($password1, $password2, $cryptType = "md5")
  100.     {
  101.         $this->log('Auth_Container::verifyPassword() called.', AUTH_LOG_DEBUG);
  102.         switch ($cryptType) {
  103.             case "crypt" :
  104.                 return ((string)crypt($password1, $password2) === (string)$password2);
  105.                 break;
  106.             case "none" :
  107.             case "" :
  108.                 return ((string)$password1 === (string)$password2);
  109.                 break;
  110.             case "md5" :
  111.                 return ((string)md5($password1) === (string)$password2);
  112.                 break;
  113.             default :
  114.                 if (function_exists($cryptType)) {
  115.                     return ((string)$cryptType($password1) === (string)$password2);
  116.                 } elseif (method_exists($this,$cryptType)) { 
  117.                     return ((string)$this->$cryptType($password1) === (string)$password2);
  118.                 } else {
  119.                     return false;
  120.                 }
  121.                 break;
  122.         }
  123.     }
  124.  
  125.     // }}}
  126.     // {{{ supportsChallengeResponse()
  127.     
  128.     /**
  129.       * Returns true if the container supports Challenge Response 
  130.       * password authentication
  131.       */
  132.     function supportsChallengeResponse()
  133.     {
  134.         return(false);
  135.     }
  136.  
  137.     // }}}
  138.     // {{{ getCryptType()
  139.     
  140.     /**
  141.       * Returns the crypt current crypt type of the container
  142.       *
  143.       * @return string
  144.       */
  145.     function getCryptType()
  146.     {
  147.         return('');
  148.     }
  149.  
  150.     // }}}
  151.     // {{{ listUsers()
  152.  
  153.     /**
  154.      * List all users that are available from the storage container
  155.      */
  156.     function listUsers()
  157.     {
  158.         $this->log('Auth_Container::listUsers() called.', AUTH_LOG_DEBUG);
  159.         return AUTH_METHOD_NOT_SUPPORTED;
  160.     }
  161.  
  162.     // }}}
  163.     // {{{ getUser()
  164.  
  165.     /**
  166.      * Returns a user assoc array
  167.      *
  168.      * Containers which want should overide this
  169.      *
  170.      * @param string The username
  171.      */
  172.     function getUser($username)
  173.     {
  174.         $this->log('Auth_Container::getUser() called.', AUTH_LOG_DEBUG);
  175.         $users = $this->listUsers();
  176.         if ($users === AUTH_METHOD_NOT_SUPPORTED) {
  177.             return AUTH_METHOD_NOT_SUPPORTED;
  178.         }
  179.         for ($i=0; $c = count($users), $i<$c; $i++) {
  180.             if ($users[$i]['username'] == $username) {
  181.                 return $users[$i];
  182.             }
  183.         }
  184.         return false;
  185.     }
  186.  
  187.     // }}}
  188.     // {{{ addUser()
  189.  
  190.     /**
  191.      * Add a new user to the storage container
  192.      *
  193.      * @param string Username
  194.      * @param string Password
  195.      * @param array  Additional information
  196.      *
  197.      * @return boolean
  198.      */
  199.     function addUser($username, $password, $additional=null)
  200.     {
  201.         $this->log('Auth_Container::addUser() called.', AUTH_LOG_DEBUG);
  202.         return AUTH_METHOD_NOT_SUPPORTED;
  203.     }
  204.  
  205.     // }}}
  206.     // {{{ removeUser()
  207.  
  208.     /**
  209.      * Remove user from the storage container
  210.      *
  211.      * @param string Username
  212.      */
  213.     function removeUser($username)
  214.     {
  215.         $this->log('Auth_Container::removeUser() called.', AUTH_LOG_DEBUG);
  216.         return AUTH_METHOD_NOT_SUPPORTED;
  217.     }
  218.  
  219.     // }}}
  220.     // {{{ changePassword()
  221.  
  222.     /**
  223.      * Change password for user in the storage container
  224.      *
  225.      * @param string Username
  226.      * @param string The new password
  227.      */
  228.     function changePassword($username, $password)
  229.     {
  230.         $this->log('Auth_Container::changePassword() called.', AUTH_LOG_DEBUG);
  231.         return AUTH_METHOD_NOT_SUPPORTED;
  232.     }
  233.  
  234.     // }}}
  235.     // {{{ log()
  236.  
  237.     /**
  238.      * Log a message to the Auth log
  239.      *
  240.      * @param string The message
  241.      * @param int
  242.      * @return boolean
  243.      */
  244.     function log($message, $level = AUTH_LOG_DEBUG) {
  245.  
  246.         if (is_null($this->_auth_obj)) {
  247.  
  248.             return false;
  249.  
  250.         } else {
  251.  
  252.             return $this->_auth_obj->log($message, $level);
  253.  
  254.         }
  255.  
  256.     }
  257.  
  258.     // }}}
  259.  
  260. }
  261.  
  262. ?>
  263.