root/releases/elgg0.8rc2/auth/multiple/lib.php

Revision 975, 2.3 kB (checked in by misja, 2 years ago)

New ini based authentication plugin to handle multiple authentication handlers.

Line 
1 <?php
2
3 /**
4  * Authenticate a user using mulitple authentication providers
5  *
6  * <p>Authenticate a user using authentication providers defined
7  * in an ini based file. The name of this file is fixed and
8  * should be called <tt>auth.ini</tt>. Location for this file should
9  * be defined in <tt>config.php</tt> in the <tt>$CFG->auth_multiple_ini</tt>
10  * directive. It is best to place this file outside of your document
11  * root since it may contain sensitive inforation.</p>
12  *
13  * <p>This function will try the providers one by one and will stop
14  * if one returns a valid result. Else it will default to basic
15  * elgg (database) authentication and return that result.</p>
16  *
17  * @author Misja Hoebe
18  * @since 0.7
19  * @package elgg
20  * @subpackage elgg.auth.multiple
21  * @param string username
22  * @param string password
23  * @return mixed authentication result
24  */
25 function multiple_authenticate_user_login($username, $password)
26 {
27     global $CFG, $messages;
28
29     $auth_config = null;
30
31     // Check if an auth.ini location is defined
32     if(!$CFG->auth_multiple_ini)
33     {
34         $messages[] = 'No "auth.ini" location defined';
35
36         return false;
37     }
38
39     // and if the file exists
40     if (!file_exists($CFG->auth_multiple_ini))
41     {
42         $messages[] = 'File "auth.ini" does not exist';
43
44         return false;
45     }
46     else
47     {
48         // Load the file
49         $auth_config = parse_ini_file($CFG->auth_multiple_ini, true);
50     }
51
52     // Walk through the config values
53     foreach ($auth_config as $key => $settings)
54     {
55         // Set the configuration parameters
56         foreach ($settings as $setting => $value)
57         {
58             $CFG->{$setting} = $value;
59         }
60
61         // All done call the provider
62         require_once($CFG->dirroot . "auth/$CFG->auth/lib.php");
63
64         $function = $CFG->auth . "_authenticate_user_login";
65
66         $result = $function($username, $password);
67
68         if ($result == false)
69         {
70             continue;
71         }
72         else
73         {
74             // We're happy
75             return $result;
76         }
77     }
78
79     // If we have reached this point no provider has returned true,
80     // so we use the internal authentication code as a final resort
81
82     // Reset to internal
83     $CFG->auth = 'internal';
84
85     require_once($CFG->dirroot . "auth/internal/lib.php");
86
87     return internal_authenticate_user_login($username, $password);
88 }
89 ?>
90
Note: See TracBrowser for help on using the browser.