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

Source for file Auth.php

Documentation is available at Auth.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Martin Jansen <mj@php.net>                                  |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Auth.php,v 1.86 2004/07/04 16:52:20 yavo Exp $
  20. //
  21.  
  22. define('AUTH_IDLED',       -1);
  23. define('AUTH_EXPIRED',     -2);
  24. define('AUTH_WRONG_LOGIN'-3);
  25. define('AUTH_METHOD_NOT_SUPPORTED'-4);
  26. define('AUTH_SECURITY_BREACH'-5);
  27.  
  28. /**
  29.  * PEAR::Auth
  30.  *
  31.  * The PEAR::Auth class provides methods for creating an
  32.  * authentication system using PHP.
  33.  *
  34.  * @author  Martin Jansen <mj@php.net>
  35.  * @package Auth
  36.  * @version $Revision: 1.86 $
  37.  */
  38. class Auth {
  39.  
  40.     /**
  41.      * Auth lifetime in seconds
  42.      *
  43.      * If this variable is set to 0, auth never expires
  44.      *
  45.      * @var  integer 
  46.      * @see  setExpire(), checkAuth()
  47.      */
  48.     var $expire = 0;
  49.  
  50.     /**
  51.      * Has the auth session expired?
  52.      *
  53.      * @var   bool 
  54.      * @see   checkAuth()
  55.      */
  56.     var $expired = false;
  57.  
  58.     /**
  59.      * Maximum idletime in seconds
  60.      *
  61.      * The difference to $expire is, that the idletime gets
  62.      * refreshed each time checkAuth() is called. If this
  63.      * variable is set to 0, idletime is never checked.
  64.      *
  65.      * @var integer 
  66.      * @see setIdle(), checkAuth()
  67.      */
  68.     var $idle = 0;
  69.  
  70.     /**
  71.      * Is the maximum idletime over?
  72.      *
  73.      * @var boolean 
  74.      * @see checkAuth()
  75.      */
  76.     var $idled = false;
  77.  
  78.     /**
  79.      * Storage object
  80.      *
  81.      * @var object 
  82.      * @see Auth(), validateLogin()
  83.      */
  84.     var $storage = '';
  85.  
  86.     /**
  87.      * User-defined function that creates the login screen
  88.      *
  89.      * @var string 
  90.      */
  91.     var $loginFunction = '';
  92.  
  93.     /**
  94.      * Should the login form be displayed
  95.      *
  96.      * @var   bool 
  97.      * @see   setShowlogin()
  98.      */
  99.     var $showLogin = true;
  100.     
  101.     /**
  102.       * Is Login Allowed from this page
  103.       *
  104.       * @var  bool 
  105.       * @see setAllowLogin
  106.       */
  107.     var $allowLogin = true;
  108.  
  109.     /**
  110.      * Current authentication status
  111.      *
  112.      * @var string 
  113.      */
  114.     var $status = '';
  115.  
  116.     /**
  117.      * Username
  118.      *
  119.      * @var string 
  120.      */
  121.     var $username = '';
  122.  
  123.     /**
  124.      * Password
  125.      *
  126.      * @var string 
  127.      */
  128.     var $password = '';
  129.  
  130.     /**
  131.      * Login callback function name
  132.      *
  133.      * @var string 
  134.      * @see setLoginCallback()
  135.      */
  136.     var $loginCallback = '';
  137.  
  138.     /**
  139.      * Failed Login callback function name
  140.      *
  141.      * @var string 
  142.      * @see setLoginFailedCallback()
  143.      */
  144.     var $loginFailedCallback = '';
  145.  
  146.     /**
  147.      * Logout callback function name
  148.      *
  149.      * @var string 
  150.      * @see setLogoutCallback()
  151.      */
  152.     var $logoutCallback = '';
  153.  
  154.     /**
  155.      * Auth session-array name
  156.      *
  157.      * @var string 
  158.      */
  159.     var $_sessionName '_authsession';
  160.     
  161.     /**
  162.      * Package Version
  163.      *
  164.      * @var string 
  165.      */
  166.     var $version = "@version@";
  167.  
  168.     /**
  169.      * Flag to use advanced security
  170.      * When set extra checks will be made to see if the
  171.      * user's IP or useragent have changed across requests.
  172.      * Turned off by default to preserve BC.
  173.      *
  174.      * @var boolean 
  175.      */     
  176.     var $advancedsecurity = false;
  177.     
  178.     /**
  179.      * Username key in POST array
  180.      *
  181.      * @var string 
  182.      */
  183.     var $_postUsername 'username';
  184.     
  185.     /**
  186.      * Password key in POST array
  187.      *
  188.      * @var string 
  189.      */
  190.     var $_postPassword 'password';
  191.     
  192.     /**
  193.      * Holds a reference to the session auth variable
  194.      * @var array 
  195.      */
  196.     var $session;
  197.  
  198.     /**
  199.      * Holds a reference to the global server variable
  200.      * @var array 
  201.      */
  202.     var $server;
  203.  
  204.     /**
  205.      * Holds a reference to the global post variable
  206.      * @var array 
  207.      */
  208.     var $post;
  209.  
  210.     /**
  211.      * Holds a reference to the global cookie variable
  212.      * @var array 
  213.      */
  214.     var $cookie;
  215.  
  216.     /**
  217.      * A hash to hold various superglobals as reference
  218.      * @var array 
  219.      */
  220.     var $authdata;
  221.     
  222.     /**
  223.       * How many times has checkAuth been called
  224.       * var int
  225.       */
  226.     var $authChecks = 0;
  227.  
  228.     /**
  229.      * Constructor
  230.      *
  231.      * Set up the storage driver.
  232.      *
  233.      * @param string    Type of the storage driver
  234.      * @param mixed     Additional options for the storage driver
  235.      *                   (example: if you are using DB as the storage
  236.      *                    driver, you have to pass the dsn string here)
  237.      *
  238.      * @param string    Name of the function that creates the login form
  239.      * @param boolean   Should the login form be displayed if neccessary?
  240.      * @return void 
  241.      */
  242.     function Auth($storageDriver$options ''$loginFunction ''$showLogin = true)
  243.     {
  244.         $this->applyAuthOptions($options);
  245.  
  246.         // Start the session suppress error if already started
  247.         @session_start();
  248.  
  249.         // Make Sure Auth session variable is there
  250.         if!isset($_SESSION[$this->_sessionName]&& !isset($GLOBALS['HTTP_SESSION_VARS'][$this->_sessionName]) ) {
  251.             session_register($this->_sessionName);
  252.         }
  253.  
  254.         // Assign Some globals to internal references, this will replace _importGlobalVariable
  255.         isset($_SESSION$this->session =$_SESSION[$this->_sessionName$this->session =$GLOBALS['HTTP_SESSION_VARS'][$this->_sessionName;
  256.         isset($_SERVER$this->server =$_SERVER $this->server =$GLOBALS['HTTP_SERVER_VARS'];
  257.         isset($_POST$this->post =$_POST $this->post =$GLOBALS['HTTP_POST_VARS'];
  258.         isset($_COOKIE$this->cookie =$_COOKIE $this->cookie =$GLOBALS['HTTP_COOKIE_VARS'];
  259.         //isset($_GET) ? $var = &$_GET : $var = &$GLOBALS['HTTP_GET_VARS'];
  260.  
  261.         if ($loginFunction != '' && is_callable($loginFunction)) {
  262.             $this->loginFunction = $loginFunction;
  263.         }
  264.  
  265.         if (is_bool($showLogin)) {
  266.             $this->showLogin = $showLogin;
  267.         }
  268.  
  269.         if (is_object($storageDriver)) {
  270.             $this->storage =$storageDriver;
  271.             // Pass a reference to auth to the container, ugly but works
  272.             // this is used by the DB container to use method setAuthData not staticaly.
  273.             $this->storage->_auth_obj =$this;
  274.         else {
  275.             // $this->storage = $this->_factory($storageDriver, $options);
  276.             // 
  277.             $this->storage_driver $storageDriver;
  278.             $this->storage_options =$options;
  279.         }
  280.     }
  281.     
  282.     /**
  283.       * Set the Auth options
  284.       *
  285.       * Some options which are Auth specific will be applied
  286.       * the rest will be left for usage by the container
  287.       * @param array An array of Auth options
  288.       * @return array The options which were not applied
  289.       */
  290.     function &applyAuthOptions(&$options{
  291.         if(is_array($options)){
  292.             if (!empty($options['sessionName'])) {
  293.                 $this->_sessionName $options['sessionName'];
  294.                 unset($options['sessionName']);
  295.             }
  296.             if (!empty($options['allowLogin'])) {
  297.                 $this->_sessionName $options['sessionName'];
  298.                 unset($options['sessionName']);
  299.             }
  300.             if (!empty($options['postUsername'])) {
  301.                 $this->_postUsername $options['postUsername'];
  302.                 unset($options['postUsername']);
  303.             }
  304.             if (!empty($options['postPassword'])) {
  305.                 $this->_postPassword $options['postPassword'];
  306.                 unset($options['postPassword']);
  307.             }
  308.             if (!empty($options['advancedsecurity'])) {
  309.                 $this->advancedsecurity = $options['advancedsecurity'];
  310.                 unset($options['advancedsecurity']);
  311.             }
  312.         }
  313.         return($options);
  314.     }
  315.     
  316.     /**
  317.       * Load Storage Driver if not already loaded
  318.       *
  319.       * Suspend storage instantiation to make Auth lighter to use
  320.       * for calls which do not require login
  321.       * @return bool True if the conainer is loaded, false if the container is already loaded
  322.       */
  323.     function _loadStorage({
  324.         if(!is_object($this->storage)) {
  325.             $this->storage =$this->_factory($this->storage_driver$this->storage_options);
  326.             $this->storage->_auth_obj =$this;
  327.             return(true);
  328.         }
  329.         return(false);
  330.     }
  331.  
  332.     /**
  333.      * Return a storage driver based on $driver and $options
  334.      *
  335.      * @static
  336.      * @param  string $driver  Type of storage class to return
  337.      * @param  string $options Optional parameters for the storage class
  338.      * @return object Object   Storage object
  339.      * @access private
  340.      */
  341.     function &_factory($driver$options ''{
  342.         $storage_class 'Auth_Container_' $driver;
  343.         require_once('Auth/Container/' $driver '.php');
  344.         return new $storage_class($options);
  345.     }
  346.  
  347.     /**
  348.      * Assign data from login form to internal values
  349.      *
  350.      * This function takes the values for username and password
  351.      * from $HTTP_POST_VARS/$_POST and assigns them to internal variables.
  352.      * If you wish to use another source apart from $HTTP_POST_VARS/$_POST,
  353.      * you have to derive this function.
  354.      *
  355.      * @global $HTTP_POST_VARS, $_POST 
  356.      * @see    Auth
  357.      * @return void 
  358.      * @access private
  359.      */
  360.     function assignData({
  361.         if (isset($this->post[$this->_postUsername]&& $this->post[$this->_postUsername!= ''{
  362.             $this->username = (get_magic_quotes_gpc(== 1 ? stripslashes($this->post[$this->_postUsername]$this->post[$this->_postUsername]);
  363.         }
  364.         if (isset($this->post[$this->_postPassword]&& $this->post[$this->_postPassword!= ''{
  365.             $this->password = (get_magic_quotes_gpc(== 1 ? stripslashes($this->post[$this->_postPassword]$this->post[$this->_postPassword);
  366.         }
  367.     }
  368.  
  369.     /**
  370.      * Start new auth session
  371.      *
  372.      * @return void 
  373.      * @access public
  374.      */
  375.     function start({
  376.         $this->assignData();
  377.         if (!$this->checkAuth(&& $this->allowLogin{
  378.             $this->login();
  379.         }
  380.     }
  381.  
  382.     /**
  383.      * Login function
  384.      *
  385.      * @return void 
  386.      * @access private
  387.      */
  388.     function login({
  389.         $login_ok = false;
  390.         $this->_loadStorage();
  391.         // Check if using challenge responce
  392.         (isset($this->post['authsecret']&& $this->post['authsecret'== 1$usingChap = true : $usingChap = false;
  393.  
  394.         /**
  395.          * When the user has already entered a username,
  396.          * we have to validate it.
  397.          */
  398.         if (!empty($this->username)) {
  399.             if (true === $this->storage->fetchData($this->username$this->password$usingChap)) {
  400.                 $this->session['challengekey'md5($this->username.$this->password);
  401.                 $login_ok = true;
  402.             }
  403.         }
  404.  
  405.         if (!empty($this->username&& $login_ok{
  406.             $this->setAuth($this->username);
  407.             if (is_callable($this->loginCallback)) {
  408.                 call_user_func_array($this->loginCallbackarray($this->username&$this) );
  409.             }
  410.         }
  411.  
  412.         /**
  413.          * If the login failed or the user entered no username,
  414.          * output the login screen again.
  415.          */
  416.         if (!empty($this->username&& !$login_ok{
  417.             $this->status = AUTH_WRONG_LOGIN;
  418.             if (is_callable($this->loginFailedCallback)) {
  419.                 call_user_func_array($this->loginFailedCallbackarray($this->username&$this) );
  420.             }
  421.         }
  422.  
  423.         if ((empty($this->username|| !$login_ok&& $this->showLogin{
  424.             if (is_callable($this->loginFunction)) {
  425.                 call_user_func_array($this->loginFunctionarray($this->username$this->status&$this) );
  426.             else {
  427.                 include_once('Auth/Frontend/Html.php');
  428.                 Auth_Frontend_Html::render($this$this->username);
  429.             }
  430.         else {
  431.             return;
  432.         }
  433.     }
  434.  
  435.     /**
  436.      * Set the maximum expire time
  437.      *
  438.      * @param  integer time in seconds
  439.      * @param  bool    add time to current expire time or not
  440.      * @return void 
  441.      * @access public
  442.      */
  443.     function setExpire($time$add = false{
  444.         $add $this->expire += $time $this->expire = $time;
  445.     }
  446.  
  447.     /**
  448.      * Set the maximum idle time
  449.      *
  450.      * @param  integer time in seconds
  451.      * @param  bool    add time to current maximum idle time or not
  452.      * @return void 
  453.      * @access public
  454.      */
  455.     function setIdle($time$add = false{
  456.         $add $this->idle += $time $this->idle = $time;
  457.     }
  458.  
  459.     /**
  460.      * Set name of the session to a customized value.
  461.      *
  462.      * If you are using multiple instances of PEAR::Auth
  463.      * on the same domain, you can change the name of
  464.      * session per application via this function.
  465.      *
  466.      * @param  string New name for the session
  467.      * @return void 
  468.      * @access public
  469.      */
  470.     function setSessionname($name 'PHPSESSID'{
  471.         @session_name($name);
  472.     }
  473.  
  474.     /**
  475.      * Should the login form be displayed if neccessary?
  476.      *
  477.      * @param  bool    show login form or not
  478.      * @return void 
  479.      * @access public
  480.      */
  481.     function setShowLogin($showLogin = true{
  482.         $this->showLogin = $showLogin;
  483.     }
  484.  
  485.     /**
  486.      * Should the login form be displayed if neccessary?
  487.      *
  488.      * @param  bool    show login form or not
  489.      * @return void 
  490.      * @access public
  491.      */
  492.     function setAllowLogin($allowLogin = true{
  493.         $this->allowLogin = $allowLogin;
  494.     }
  495.     
  496.     /**
  497.      * Register a callback function to be called on user login.
  498.      * The function will receive two parameters, the username and a reference to the auth object.
  499.      *
  500.      * @param  string  callback function name
  501.      * @return void 
  502.      * @see    setLogoutCallback()
  503.      * @access public
  504.      */
  505.     function setLoginCallback($loginCallback{
  506.         $this->loginCallback = $loginCallback;
  507.     }
  508.  
  509.     /**
  510.      * Register a callback function to be called on failed user login.
  511.      * The function will receive a single parameter, the username and a reference to the auth object.
  512.      *
  513.      * @param  string  callback function name
  514.      * @return void 
  515.      * @access public
  516.      */
  517.     function setFailedLoginCallback($loginFailedCallback{
  518.         $this->loginFailedCallback = $loginFailedCallback;
  519.     }
  520.  
  521.     /**
  522.      * Register a callback function to be called on user logout.
  523.      * The function will receive three parameters, the username and a reference to the auth object.
  524.      *
  525.      * @param  string  callback function name
  526.      * @return void 
  527.      * @see    setLoginCallback()
  528.      * @access public
  529.      */
  530.     function setLogoutCallback($logoutCallback{
  531.         $this->logoutCallback = $logoutCallback;
  532.     }
  533.  
  534.     /**
  535.      * Register additional information that is to be stored
  536.      * in the session.
  537.      *
  538.      * @param  string  Name of the data field
  539.      * @param  mixed   Value of the data field
  540.      * @param  boolean Should existing data be overwritten? (default
  541.      *                  is true)
  542.      * @return void 
  543.      * @access public
  544.      */
  545.     function setAuthData($name$value$overwrite = true{
  546.         if (!empty($this->session['data'][$name]&& $overwrite == false{
  547.             return;
  548.         }
  549.         $this->session['data'][$name$value;
  550.     }
  551.  
  552.     /**
  553.      * Get additional information that is stored in the session.
  554.      *
  555.      * If no value for the first parameter is passed, the method will
  556.      * return all data that is currently stored.
  557.      *
  558.      * @param  string Name of the data field
  559.      * @return mixed  Value of the data field.
  560.      * @access public
  561.      */
  562.     function getAuthData($name = null{
  563.         if (!isset($this->session['data'])) {
  564.             return null;
  565.         }
  566.         if (!is_null($name)) {
  567.             return $this->session['data'][$name];
  568.         }
  569.         return $this->session['data'];
  570.     }
  571.  
  572.     /**
  573.      * Register variable in a session telling that the user
  574.      * has logged in successfully
  575.      *
  576.      * @param  string Username
  577.      * @return void 
  578.      * @access public
  579.      */
  580.     function setAuth($username{
  581.         if (!isset($this->session|| !is_array($this->session)) {
  582.             $this->session = array();
  583.         }
  584.  
  585.         if (!isset($this->session['data'])) {
  586.             $this->session['data'= array();
  587.         }
  588.  
  589.         $this->session['sessionip'= isset($this->server['REMOTE_ADDR']$this->server['REMOTE_ADDR''';
  590.         $this->session['sessionuseragent'= isset($this->server['HTTP_USER_AGENT']$this->server['HTTP_USER_AGENT''';
  591.  
  592.         // This should be set by the container to something more safe
  593.         // Like md5(passwd.microtime)
  594.         if(empty($this->session['challengekey'])) {
  595.             $this->session['challengekey'md5($username.microtime());
  596.         }
  597.  
  598.         $this->session['challengecookie'md5($this->session['challengekey'].microtime());
  599.         setcookie('authchallenge'$this->session['challengecookie']);
  600.  
  601.         $this->session['registered'= true;
  602.         $this->session['username']   $username;
  603.         $this->session['timestamp']  time();
  604.         $this->session['idle']       time();
  605.     }
  606.     
  607.     /**
  608.       * Enables advanced security checks
  609.       *
  610.       * Currently only ip change and useragent change
  611.       * are detected
  612.       * @todo Add challenge cookies - Create a cookie which changes every time
  613.       *        and contains some challenge key which the server can verify with a session var
  614.       *        cookie might need to be crypted (user pass)
  615.       * @param bool Enable or disable
  616.       * @return void 
  617.       * @access public
  618.       */
  619.     function setAdvancedSecurity($flag=true{
  620.         $this->advancedsecurity = $flag;
  621.     }
  622.  
  623.     /**
  624.      * Checks if there is a session with valid auth information.
  625.      *
  626.      * @access private
  627.      * @return boolean  Whether or not the user is authenticated.
  628.      */
  629.     function checkAuth({
  630.         $this->authChecks++;
  631.         if (isset($this->session)) {
  632.             // Check if authentication session is expired
  633.             if ($this->expire > 0 &&
  634.                 isset($this->session['timestamp']&&
  635.                 ($this->session['timestamp'$this->expiretime()) {
  636.                 $this->expired = true;
  637.                 $this->status = AUTH_EXPIRED;
  638.                 $this->logout();
  639.                 return false;
  640.             }
  641.  
  642.             // Check if maximum idle time is reached
  643.             if ($this->idle > 0 &&
  644.                 isset($this->session['idle']&&
  645.                 ($this->session['idle'$this->idletime()) {
  646.                 $this->idled = true;
  647.                 $this->status = AUTH_IDLED;
  648.                 $this->logout();
  649.                 return false;
  650.             }
  651.  
  652.             if (isset($this->session['registered']&&
  653.                 isset($this->session['username']&&
  654.                 $this->session['registered'== true &&
  655.                 $this->session['username'!= ''{
  656.                 Auth::updateIdle();
  657.                 // Only Generate the challenge once
  658.                 if($this->authChecks == 1{
  659.                     $this->session['challengecookieold'$this->session['challengecookie'];
  660.                     $this->session['challengecookie'md5($this->session['challengekey'].microtime());
  661.                     setcookie('authchallenge'$this->session['challengecookie']);
  662.                 }
  663.  
  664.                 if ($this->advancedsecurity{
  665.                     // Check for ip change
  666.                     if isset($this->server['REMOTE_ADDR']&& $this->session['sessionip'!= $this->server['REMOTE_ADDR']{
  667.                         // Check if the IP of the user has changed, if so we assume a man in the middle attack and log him out
  668.                         $this->expired = true;
  669.                         $this->status = AUTH_SECURITY_BREACH;
  670.                         $this->logout();
  671.                         return false;
  672.                     }
  673.                     // Check for useragent change
  674.                     if isset($this->server['HTTP_USER_AGENT']&& $this->session['sessionuseragent'!= $this->server['HTTP_USER_AGENT']{
  675.                         // Check if the User-Agent of the user has changed, if so we assume a man in the middle attack and log him out
  676.                         $this->expired = true;
  677.                         $this->status = AUTH_SECURITY_BREACH;
  678.                         $this->logout();
  679.                         return false;
  680.                     }
  681.     
  682.                     // Check challenge cookie here, if challengecookieold is not set this is the first time and check is skipped
  683.                     if isset($this->session['challengecookieold']&& $this->session['challengecookieold'!= $this->cookie['authchallenge']{
  684.                         $this->expired = true;
  685.                         $this->status = AUTH_SECURITY_BREACH;
  686.                         $this->logout();
  687.                         $this->login();
  688.                         return false;
  689.                     }
  690.                 }
  691.  
  692.                 return true;
  693.             }
  694.         }
  695.         return false;
  696.     }
  697.  
  698.     /**
  699.      * Statically checks if there is a session with valid auth information.
  700.      *
  701.      * @access private
  702.      * @see checkAuth
  703.      * @return boolean  Whether or not the user is authenticated.
  704.      */
  705.     function staticCheckAuth($options = null{
  706.         static $staticAuth;
  707.         if(!isset($staticAuth)) {
  708.             $staticAuth = new Auth('null'$options);
  709.         }
  710.         return$staticAuth->checkAuth() );
  711.     }
  712.  
  713.     /**
  714.      * Has the user been authenticated?
  715.      *
  716.      * @access public
  717.      * @return bool  True if the user is logged in, otherwise false.
  718.      */
  719.     function getAuth({
  720.         if isset($this->session['registered']) ) {
  721.             $this->session['registered'];
  722.         }
  723.         return false;
  724.     }
  725.  
  726.     /**
  727.      * Logout function
  728.      *
  729.      * This function clears any auth tokens in the currently
  730.      * active session and executes the logout callback function,
  731.      * if any
  732.      *
  733.      * @access public
  734.      * @return void 
  735.      */
  736.     function logout({
  737.         if (is_callable($this->logoutCallback)) {
  738.             call_user_func_array($this->logoutCallbackarray($this->session['username']&$this) );
  739.         }
  740.  
  741.         $this->username = '';
  742.         $this->password = '';
  743.         
  744.         $this->session = null;
  745.     }
  746.  
  747.     /**
  748.      * Update the idletime
  749.      *
  750.      * @access private
  751.      * @return void 
  752.      */
  753.     function updateIdle()
  754.     {
  755.         $this->session['idle'time();
  756.     }
  757.  
  758.     /**
  759.      * Get the username
  760.      *
  761.      * @return string 
  762.      * @access public
  763.      */
  764.     function getUsername()
  765.     {
  766.         if (isset($this->session['username'])) {
  767.             return($this->session['username']);
  768.         }
  769.         return('');
  770.     }
  771.  
  772.     /**
  773.      * Get the current status
  774.      *
  775.      * @return string 
  776.      * @access public
  777.      */
  778.     function getStatus()
  779.     {
  780.         return $this->status;
  781.     }
  782.     
  783.     /**
  784.      * Gets the post varible used for the username
  785.      * 
  786.      * @return string 
  787.      * @access public
  788.      */
  789.     function getPostUsernameField({
  790.         return($this->_postUsername);
  791.     }
  792.  
  793.     /**
  794.      * Gets the post varible used for the username
  795.      * 
  796.      * @return string 
  797.      * @access public
  798.      */
  799.     function getPostPasswordField({
  800.         return($this->_postPassword);
  801.     }
  802.  
  803.     /**
  804.      * Returns the time up to the session is valid
  805.      *
  806.      * @access public
  807.      * @return integer 
  808.      */
  809.     function sessionValidThru()
  810.     {
  811.         if (!isset($this->session['idle'])) {
  812.             return 0;
  813.         }
  814.         return ($this->session['idle'$this->idle);
  815.     }
  816.  
  817.     /**
  818.      * List all users that are currently available in the storage
  819.      * container
  820.      *
  821.      * @access public
  822.      * @return array 
  823.      */
  824.     function listUsers()
  825.     {
  826.         $this->_loadStorage();
  827.         return $this->storage->listUsers();
  828.     }
  829.  
  830.     /**
  831.      * Add user to the storage container
  832.      *
  833.      * @access public
  834.      * @param  string Username
  835.      * @param  string Password
  836.      * @param  mixed  Additional parameters
  837.      * @return mixed  True on success, PEAR error object on error
  838.      *                 and AUTH_METHOD_NOT_SUPPORTED otherwise.
  839.      */
  840.     function addUser($username$password$additional '')
  841.     {
  842.         $this->_loadStorage();
  843.         return $this->storage->addUser($username$password$additional);
  844.     }
  845.  
  846.     /**
  847.      * Remove user from the storage container
  848.      *
  849.      * @access public
  850.      * @param  string Username
  851.      * @return mixed  True on success, PEAR error object on error
  852.      *                 and AUTH_METHOD_NOT_SUPPORTED otherwise.
  853.      */
  854.     function removeUser($username)
  855.     {
  856.         $this->_loadStorage();
  857.         return $this->storage->removeUser($username);
  858.     }
  859.  
  860.     /**
  861.      * Change password for user in the storage container
  862.      *
  863.      * @access public
  864.      * @param string Username
  865.      * @param string The new password
  866.      * @return mixed True on success, PEAR error object on error
  867.      *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
  868.      */
  869.     function changePassword($username$password)
  870.     {
  871.         $this->_loadStorage();
  872.         return $this->storage->changePassword($username$password);
  873.     }
  874. }
  875. ?>

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