Auth_Container_Multiple

Auth_Container_Multiple – Authenticate against multiple Auth_Containers

Multiple

This container provides a facility to attempt to authenticate against multiple Auth_Containers in order.

If a container's getAuthData() returns true Auth_Container_Multiple will return true.

When a container's getAuthData() returns false Auth_Container_Multiple will continue on through the list of available containers until a successful login is found or the list of containers is expired.

On receipt of an error from getAuthData() Auth_Container_Multiple will abort checking further containers and return the error.

The storage-specific argument for the Auth constructor() is an array of container configurations. Each container configuration has the following options:

Available Options
Option Data Type Default value Description
"type" string " The type of container to instanciate. This is the same value as used in the first parameter of the Auth constructor() .
"options" array array() This is the standard array of options required for the container.

Example usage of Auth_Container_Multiple

<?php
require_once "Auth.php";
require_once 
'Log.php';
require_once 
'Log/observer.php';

// Callback function to display login form
function loginFunction($username null$status null, &$auth null)
{
    
/*
     * Change the HTML output so that it fits to your
     * application.
     */
    
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">";
    echo 
"Username: <input type=\"text\" name=\"username\"><br/>";
    echo 
"Password: <input type=\"password\" name=\"password\"><br/>";
    echo 
"<input type=\"submit\">";
    echo 
"</form>";
}

class 
Auth_Log_Observer extends Log_observer {

    var 
$messages = array();

    function 
notify($event) {

        
$this->messages[] = $event;

    }

}

$options = array(
    
'enableLogging' => true,
    array(
        
'type' => 'Array',
        
'options' => array(
            
'cryptType' => 'md5',
            
'users' => array(
                
'guest' => md5('password'),
            ),
        ),
    ),
    array(
        
'type' => 'Array',
        
'options' => array(
            
'cryptType' => 'md5',
            
'users' => array(
                
'admin' => md5('password'),
            ),
        ),
    ),
);
$a = new Auth("Multiple"$options"loginFunction");

$infoObserver = new Auth_Log_Observer(PEAR_LOG_INFO);

$a->attachLogObserver($infoObserver);

$debugObserver = new Auth_Log_Observer(PEAR_LOG_DEBUG);

$a->attachLogObserver($debugObserver);

$a->start();

if (
$a->checkAuth()) {
    
/*
     * The output of your site goes here.
     */
    
print "Authentication Successful.<br/>";
}

print 
'<h3>Logging Output:</h3>'
    
.'<b>PEAR_LOG_INFO level messages:</b><br/>';

foreach (
$infoObserver->messages as $event) {
    print 
$event['priority'].': '.$event['message'].'<br/>';
}

print 
'<br/>'
    
.'<b>PEAR_LOG_DEBUG level messages:</b><br/>';

foreach (
$debugObserver->messages as $event) {
    print 
$event['priority'].': '.$event['message'].'<br/>';
}

print 
'<br/>';
?>

Note

This container has only been available since version 1.5.0.

Authenticate against a database using MDB2 (Previous) Authenticate against the PEAR website (Next)
Last updated: Wed, 16 Apr 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.