home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / Auth / Container.php < prev    next >
Encoding:
PHP Script  |  2006-04-07  |  5.3 KB  |  225 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.23 2006/03/02 06:53:08 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.3.0  File: $Revision: 1.23 $
  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.     // {{{ Auth_Container() [constructor]
  51.  
  52.     /**
  53.      * Constructor
  54.      *
  55.      * Has to be overwritten by each storage class
  56.      *
  57.      * @access public
  58.      */
  59.     function Auth_Container()
  60.     {
  61.     }
  62.  
  63.     // }}}
  64.     // {{{ fetchData()
  65.  
  66.     /**
  67.      * Fetch data from storage container
  68.      *
  69.      * Has to be overwritten by each storage class
  70.      *
  71.      * @access public
  72.      */
  73.     function fetchData($username, $password, $isChallengeResponse=false)
  74.     {
  75.     }
  76.  
  77.     // }}}
  78.     // {{{ verifyPassword()
  79.  
  80.     /**
  81.      * Crypt and verfiy the entered password
  82.      *
  83.      * @param  string Entered password
  84.      * @param  string Password from the data container (usually this password
  85.      *                is already encrypted.
  86.      * @param  string Type of algorithm with which the password from
  87.      *                the container has been crypted. (md5, crypt etc.)
  88.      *                Defaults to "md5".
  89.      * @return bool   True, if the passwords match
  90.      */
  91.     function verifyPassword($password1, $password2, $cryptType = "md5")
  92.     {
  93.         switch ($cryptType) {
  94.             case "crypt" :
  95.                 return ( crypt($password1, $password2) == $password2 );
  96.                 break;
  97.             case "none" :
  98.             case "" :
  99.                 return ($password1 == $password2);
  100.                 break;
  101.             case "md5" :
  102.                 return (md5($password1) == $password2);
  103.                 break;
  104.             default :
  105.                 if (function_exists($cryptType)) {
  106.                     return ($cryptType($password1) == $password2);
  107.                 } elseif (method_exists($this,$cryptType)) { 
  108.                     return ($this->$cryptType($password1) == $password2);
  109.                 } else {
  110.                     return false;
  111.                 }
  112.                 break;
  113.         }
  114.     }
  115.  
  116.     // }}}
  117.     // {{{ supportsChallengeResponse()
  118.     
  119.     /**
  120.       * Returns true if the container supports Challenge Response 
  121.       * password authentication
  122.       */
  123.     function supportsChallengeResponse()
  124.     {
  125.         return(false);
  126.     }
  127.  
  128.     // }}}
  129.     // {{{ getCryptType()
  130.     
  131.     /**
  132.       * Returns the crypt current crypt type of the container
  133.       *
  134.       * @return string
  135.       */
  136.     function getCryptType()
  137.     {
  138.         return('');
  139.     }
  140.  
  141.     // }}}
  142.     // {{{ listUsers()
  143.  
  144.     /**
  145.      * List all users that are available from the storage container
  146.      */
  147.     function listUsers()
  148.     {
  149.         return AUTH_METHOD_NOT_SUPPORTED;
  150.     }
  151.  
  152.     // }}}
  153.     // {{{ getUser()
  154.  
  155.     /**
  156.      * Returns a user assoc array
  157.      *
  158.      * Containers which want should overide this
  159.      *
  160.      * @param string The username
  161.      */
  162.     function getUser($username)
  163.     {
  164.         $users = $this->listUsers();
  165.         if ($users === AUTH_METHOD_NOT_SUPPORTED) {
  166.             return AUTH_METHOD_NOT_SUPPORTED;
  167.         }
  168.         for ($i=0; $c = count($users), $i<$c; $i++) {
  169.             if ($users[$i]['username'] == $username) {
  170.                 return $users[$i];
  171.             }
  172.         }
  173.         return false;
  174.     }
  175.  
  176.     // }}}
  177.     // {{{ addUser()
  178.  
  179.     /**
  180.      * Add a new user to the storage container
  181.      *
  182.      * @param string Username
  183.      * @param string Password
  184.      * @param array  Additional information
  185.      *
  186.      * @return boolean
  187.      */
  188.     function addUser($username, $password, $additional=null)
  189.     {
  190.         return AUTH_METHOD_NOT_SUPPORTED;
  191.     }
  192.  
  193.     // }}}
  194.     // {{{ removeUser()
  195.  
  196.     /**
  197.      * Remove user from the storage container
  198.      *
  199.      * @param string Username
  200.      */
  201.     function removeUser($username)
  202.     {
  203.         return AUTH_METHOD_NOT_SUPPORTED;
  204.     }
  205.  
  206.     // }}}
  207.     // {{{ changePassword()
  208.  
  209.     /**
  210.      * Change password for user in the storage container
  211.      *
  212.      * @param string Username
  213.      * @param string The new password
  214.      */
  215.     function changePassword($username, $password)
  216.     {
  217.         return AUTH_METHOD_NOT_SUPPORTED;
  218.     }
  219.  
  220.     // }}}
  221.  
  222. }
  223.  
  224. ?>
  225.