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.93 2004/08/31 06:48:22 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.93 $
  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->allowLogin = $options['allowLogin'];
  298.                 unset($options['allowLogin']);
  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.                 // BC fix Auth used to use drawLogin for this
  428.                 // call is sub classes implement this
  429.                 if(is_callable(array(&$this'drawLogin'))) {
  430.                     return $this->drawLogin($this->username&$this);
  431.                 }
  432.  
  433.                 // New Login form
  434.                 include_once('Auth/Frontend/Html.php');
  435.                 return Auth_Frontend_Html::render($this$this->username);
  436.             }
  437.         else {
  438.             return;
  439.         }
  440.     }
  441.  
  442.     /**
  443.      * Set the maximum expire time
  444.      *
  445.      * @param  integer time in seconds
  446.      * @param  bool    add time to current expire time or not
  447.      * @return void 
  448.      * @access public
  449.      */
  450.     function setExpire($time$add = false{
  451.         $add $this->expire += $time $this->expire = $time;
  452.     }
  453.  
  454.     /**
  455.      * Set the maximum idle time
  456.      *
  457.      * @param  integer time in seconds
  458.      * @param  bool    add time to current maximum idle time or not
  459.      * @return void 
  460.      * @access public
  461.      */
  462.     function setIdle($time$add = false{
  463.         $add $this->idle += $time $this->idle = $time;
  464.     }
  465.  
  466.     /**
  467.      * Set name of the session to a customized value.
  468.      *
  469.      * If you are using multiple instances of PEAR::Auth
  470.      * on the same domain, you can change the name of
  471.      * session per application via this function.
  472.      * This will chnage the name of the session variable
  473.      * auth uses to store it's data in the session
  474.      *
  475.      * @param  string New name for the session
  476.      * @return void 
  477.      * @access public
  478.      */
  479.     function setSessionName($name 'session'{
  480.         $this->_sessionName '_auth_'.$name;
  481.         isset($_SESSION$this->session =$_SESSION[$this->_sessionName$this->session =$GLOBALS['HTTP_SESSION_VARS'][$this->_sessionName;
  482.     }
  483.  
  484.     /**
  485.      * Should the login form be displayed if neccessary?
  486.      *
  487.      * @param  bool    show login form or not
  488.      * @return void 
  489.      * @access public
  490.      */
  491.     function setShowLogin($showLogin = true{
  492.         $this->showLogin = $showLogin;
  493.     }
  494.  
  495.     /**
  496.      * Should the login form be displayed if neccessary?
  497.      *
  498.      * @param  bool    show login form or not
  499.      * @return void 
  500.      * @access public
  501.      */
  502.     function setAllowLogin($allowLogin = true{
  503.         $this->allowLogin = $allowLogin;
  504.     }
  505.     
  506.     /**
  507.      * Register a callback function to be called on user login.
  508.      * The function will receive two parameters, the username and a reference to the auth object.
  509.      *
  510.      * @param  string  callback function name
  511.      * @return void 
  512.      * @see    setLogoutCallback()
  513.      * @access public
  514.      */
  515.     function setLoginCallback($loginCallback{
  516.         $this->loginCallback = $loginCallback;
  517.     }
  518.  
  519.     /**
  520.      * Register a callback function to be called on failed user login.
  521.      * The function will receive a single parameter, the username and a reference to the auth object.
  522.      *
  523.      * @param  string  callback function name
  524.      * @return void 
  525.      * @access public
  526.      */
  527.     function setFailedLoginCallback($loginFailedCallback{
  528.         $this->loginFailedCallback = $loginFailedCallback;
  529.     }
  530.  
  531.     /**
  532.      * Register a callback function to be called on user logout.
  533.      * The function will receive three parameters, the username and a reference to the auth object.
  534.      *
  535.      * @param  string  callback function name
  536.      * @return void 
  537.      * @see    setLoginCallback()
  538.      * @access public
  539.      */
  540.     function setLogoutCallback($logoutCallback{
  541.         $this->logoutCallback = $logoutCallback;
  542.     }
  543.  
  544.     /**
  545.      * Register additional information that is to be stored
  546.      * in the session.
  547.      *
  548.      * @param  string  Name of the data field
  549.      * @param  mixed   Value of the data field
  550.      * @param  boolean Should existing data be overwritten? (default
  551.      *                  is true)
  552.      * @return void 
  553.      * @access public
  554.      */
  555.     function setAuthData($name$value$overwrite = true{
  556.         if (!empty($this->session['data'][$name]&& $overwrite == false{
  557.             return;
  558.         }
  559.         $this->session['data'][$name$value;
  560.     }
  561.  
  562.     /**
  563.      * Get additional information that is stored in the session.
  564.      *
  565.      * If no value for the first parameter is passed, the method will
  566.      * return all data that is currently stored.
  567.      *
  568.      * @param  string Name of the data field
  569.      * @return mixed  Value of the data field.
  570.      * @access public
  571.      */
  572.     function getAuthData($name = null{
  573.         if (!isset($this->session['data'])) {
  574.             return null;
  575.         }
  576.         if (!is_null($name)) {
  577.             return $this->session['data'][$name];
  578.         }
  579.         return $this->session['data'];
  580.     }
  581.  
  582.     /**
  583.      * Register variable in a session telling that the user
  584.      * has logged in successfully
  585.      *
  586.      * @param  string Username
  587.      * @return void 
  588.      * @access public
  589.      */
  590.     function setAuth($username{
  591.         if (!isset($this->session|| !is_array($this->session)) {
  592.             $this->session = array();
  593.         }
  594.  
  595.         if (!isset($this->session['data'])) {
  596.             $this->session['data'= array();
  597.         }
  598.  
  599.         $this->session['sessionip'= isset($this->server['REMOTE_ADDR']$this->server['REMOTE_ADDR''';
  600.         $this->session['sessionuseragent'= isset($this->server['HTTP_USER_AGENT']$this->server['HTTP_USER_AGENT''';
  601.  
  602.         // This should be set by the container to something more safe
  603.         // Like md5(passwd.microtime)
  604.         if(empty($this->session['challengekey'])) {
  605.             $this->session['challengekey'md5($username.microtime());
  606.         }
  607.  
  608.         $this->session['challengecookie'md5($this->session['challengekey'].microtime());
  609.         setcookie('authchallenge'$this->session['challengecookie']);
  610.  
  611.         $this->session['registered'= true;
  612.         $this->session['username']   $username;
  613.         $this->session['timestamp']  time();
  614.         $this->session['idle']       time();
  615.     }
  616.     
  617.     /**
  618.       * Enables advanced security checks
  619.       *
  620.       * Currently only ip change and useragent change
  621.       * are detected
  622.       * @todo Add challenge cookies - Create a cookie which changes every time
  623.       *        and contains some challenge key which the server can verify with a session var
  624.       *        cookie might need to be crypted (user pass)
  625.       * @param bool Enable or disable
  626.       * @return void 
  627.       * @access public
  628.       */
  629.     function setAdvancedSecurity($flag=true{
  630.         $this->advancedsecurity = $flag;
  631.     }
  632.  
  633.     /**
  634.      * Checks if there is a session with valid auth information.
  635.      *
  636.      * @access private
  637.      * @return boolean  Whether or not the user is authenticated.
  638.      */
  639.     function checkAuth({
  640.         $this->authChecks++;
  641.         if (isset($this->session)) {
  642.             // Check if authentication session is expired
  643.             if ($this->expire > 0 &&
  644.                 isset($this->session['timestamp']&&
  645.                 ($this->session['timestamp'$this->expiretime()) {
  646.                 $this->expired = true;
  647.                 $this->status = AUTH_EXPIRED;
  648.                 $this->logout();
  649.                 return false;
  650.             }
  651.  
  652.             // Check if maximum idle time is reached
  653.             if ($this->idle > 0 &&
  654.                 isset($this->session['idle']&&
  655.                 ($this->session['idle'$this->idletime()) {
  656.                 $this->idled = true;
  657.                 $this->status = AUTH_IDLED;
  658.                 $this->logout();
  659.                 return false;
  660.             }
  661.  
  662.             if (isset($this->session['registered']&&
  663.                 isset($this->session['username']&&
  664.                 $this->session['registered'== true &&
  665.                 $this->session['username'!= ''{
  666.                 Auth::updateIdle();
  667.  
  668.                 if ($this->advancedsecurity{
  669.                     // Only Generate the challenge once
  670.                     if($this->authChecks == 1{
  671.                         $this->session['challengecookieold'$this->session['challengecookie'];
  672.                         $this->session['challengecookie'md5($this->session['challengekey'].microtime());
  673.                         setcookie('authchallenge'$this->session['challengecookie']);
  674.                     }
  675.                     // Check for ip change
  676.                     if isset($this->server['REMOTE_ADDR']&& $this->session['sessionip'!= $this->server['REMOTE_ADDR']{
  677.                         // Check if the IP of the user has changed, if so we assume a man in the middle attack and log him out
  678.                         $this->expired = true;
  679.                         $this->status = AUTH_SECURITY_BREACH;
  680.                         $this->logout();
  681.                         return false;
  682.                     }
  683.                     // Check for useragent change
  684.                     if isset($this->server['HTTP_USER_AGENT']&& $this->session['sessionuseragent'!= $this->server['HTTP_USER_AGENT']{
  685.                         // Check if the User-Agent of the user has changed, if so we assume a man in the middle attack and log him out
  686.                         $this->expired = true;
  687.                         $this->status = AUTH_SECURITY_BREACH;
  688.                         $this->logout();
  689.                         return false;
  690.                     }
  691.     
  692.                     // Check challenge cookie here, if challengecookieold is not set this is the first time and check is skipped
  693.                     // TODO when user open two pages similtaneuly (open in new window,open in tab) auth breach is caused 
  694.                     // find out a way around that if possible
  695.                     if isset($this->session['challengecookieold']&& $this->session['challengecookieold'!= $this->cookie['authchallenge']{
  696.                         $this->expired = true;
  697.                         $this->status = AUTH_SECURITY_BREACH;
  698.                         $this->logout();
  699.                         $this->login();
  700.                         return false;
  701.                     }
  702.                 }
  703.  
  704.                 return true;
  705.             }
  706.         }
  707.         return false;
  708.     }
  709.  
  710.     /**
  711.      * Statically checks if there is a session with valid auth information.
  712.      *
  713.      * @access private
  714.      * @see checkAuth
  715.      * @return boolean  Whether or not the user is authenticated.
  716.      */
  717.     function staticCheckAuth($options = null{
  718.         static $staticAuth;
  719.         if(!isset($staticAuth)) {
  720.             $staticAuth = new Auth('null'$options);
  721.         }
  722.         return$staticAuth->checkAuth() );
  723.     }
  724.  
  725.     /**
  726.      * Has the user been authenticated?
  727.      *
  728.      * @access public
  729.      * @return bool  True if the user is logged in, otherwise false.
  730.      */
  731.     function getAuth({
  732.         return $this->checkAuth();
  733.     }
  734.  
  735.     /**
  736.      * Logout function
  737.      *
  738.      * This function clears any auth tokens in the currently
  739.      * active session and executes the logout callback function,
  740.      * if any
  741.      *
  742.      * @access public
  743.      * @return void 
  744.      */
  745.     function logout({
  746.         if (is_callable($this->logoutCallback)) {
  747.             call_user_func_array($this->logoutCallbackarray($this->session['username']&$this) );
  748.         }
  749.  
  750.         $this->username = '';
  751.         $this->password = '';
  752.         
  753.         $this->session = null;
  754.     }
  755.  
  756.     /**
  757.      * Update the idletime
  758.      *
  759.      * @access private
  760.      * @return void 
  761.      */
  762.     function updateIdle()
  763.     {
  764.         $this->session['idle'time();
  765.     }
  766.  
  767.     /**
  768.      * Get the username
  769.      *
  770.      * @return string 
  771.      * @access public
  772.      */
  773.     function getUsername()
  774.     {
  775.         if (isset($this->session['username'])) {
  776.             return($this->session['username']);
  777.         }
  778.         return('');
  779.     }
  780.  
  781.     /**
  782.      * Get the current status
  783.      *
  784.      * @return string 
  785.      * @access public
  786.      */
  787.     function getStatus()
  788.     {
  789.         return $this->status;
  790.     }
  791.     
  792.     /**
  793.      * Gets the post varible used for the username
  794.      * 
  795.      * @return string 
  796.      * @access public
  797.      */
  798.     function getPostUsernameField({
  799.         return($this->_postUsername);
  800.     }
  801.  
  802.     /**
  803.      * Gets the post varible used for the username
  804.      * 
  805.      * @return string 
  806.      * @access public
  807.      */
  808.     function getPostPasswordField({
  809.         return($this->_postPassword);
  810.     }
  811.  
  812.     /**
  813.      * Returns the time up to the session is valid
  814.      *
  815.      * @access public
  816.      * @return integer 
  817.      */
  818.     function sessionValidThru()
  819.     {
  820.         if (!isset($this->session['idle'])) {
  821.             return 0;
  822.         }
  823.         return ($this->session['idle'$this->idle);
  824.     }
  825.  
  826.     /**
  827.      * List all users that are currently available in the storage
  828.      * container
  829.      *
  830.      * @access public
  831.      * @return array 
  832.      */
  833.     function listUsers()
  834.     {
  835.         $this->_loadStorage();
  836.         return $this->storage->listUsers();
  837.     }
  838.  
  839.     /**
  840.      * Add user to the storage container
  841.      *
  842.      * @access public
  843.      * @param  string Username
  844.      * @param  string Password
  845.      * @param  mixed  Additional parameters
  846.      * @return mixed  True on success, PEAR error object on error
  847.      *                 and AUTH_METHOD_NOT_SUPPORTED otherwise.
  848.      */
  849.     function addUser($username$password$additional '')
  850.     {
  851.         $this->_loadStorage();
  852.         return $this->storage->addUser($username$password$additional);
  853.     }
  854.  
  855.     /**
  856.      * Remove user from the storage container
  857.      *
  858.      * @access public
  859.      * @param  string Username
  860.      * @return mixed  True on success, PEAR error object on error
  861.      *                 and AUTH_METHOD_NOT_SUPPORTED otherwise.
  862.      */
  863.     function removeUser($username)
  864.     {
  865.         $this->_loadStorage();
  866.         return $this->storage->removeUser($username);
  867.     }
  868.  
  869.     /**
  870.      * Change password for user in the storage container
  871.      *
  872.      * @access public
  873.      * @param string Username
  874.      * @param string The new password
  875.      * @return mixed True on success, PEAR error object on error
  876.      *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
  877.      */
  878.     function changePassword($username$password)
  879.     {
  880.         $this->_loadStorage();
  881.         return $this->storage->changePassword($username$password);
  882.     }
  883. }
  884. ?>

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