Subversion Repositories Applications.papyrus

Rev

Rev 1173 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1173 Rev 1713
1
<?php
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
 
3
 
4
/**
4
/**
5
 * Auth_Container Base Class
5
 * Auth_Container Base Class
6
 *
6
 *
7
 * PHP versions 4 and 5
7
 * PHP versions 4 and 5
8
 *
8
 *
9
 * LICENSE: This source file is subject to version 3.01 of the PHP license
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:
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
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
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.
13
 * send a note to license@php.net so we can mail you a copy immediately.
14
 *
14
 *
15
 * @category   Authentication
15
 * @category   Authentication
16
 * @package    Auth
16
 * @package    Auth
17
 * @author     Martin Jansen <mj@php.net>
17
 * @author     Martin Jansen <mj@php.net>
18
 * @author     Adam Ashley <aashley@php.net>
18
 * @author     Adam Ashley <aashley@php.net>
19
 * @copyright  2001-2006 The PHP Group
19
 * @copyright  2001-2006 The PHP Group
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
21
 * @version    CVS: $Id: Container.php,v 1.2 2006-12-14 15:04:28 jp_milcent Exp $
21
 * @version    CVS: $Id: Container.php,v 1.3 2007-11-19 15:11:00 jp_milcent Exp $
22
 * @link       http://pear.php.net/package/Auth
22
 * @link       http://pear.php.net/package/Auth
23
 */
23
 */
24
 
24
 
25
/**
25
/**
26
 * Storage class for fetching login data
26
 * Storage class for fetching login data
27
 *
27
 *
28
 * @category   Authentication
28
 * @category   Authentication
29
 * @package    Auth
29
 * @package    Auth
30
 * @author     Martin Jansen <mj@php.net>
30
 * @author     Martin Jansen <mj@php.net>
31
 * @author     Adam Ashley <aashley@php.net>
31
 * @author     Adam Ashley <aashley@php.net>
32
 * @copyright  2001-2006 The PHP Group
32
 * @copyright  2001-2006 The PHP Group
33
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
33
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
34
 * @version    Release: 1.4.3  File: $Revision: 1.2 $
34
 * @version    Release: 1.5.4  File: $Revision: 1.3 $
35
 * @link       http://pear.php.net/package/Auth
35
 * @link       http://pear.php.net/package/Auth
36
 */
36
 */
37
class Auth_Container
37
class Auth_Container
38
{
38
{
39
 
39
 
40
    // {{{ properties
40
    // {{{ properties
41
 
41
 
42
    /**
42
    /**
43
     * User that is currently selected from the storage container.
43
     * User that is currently selected from the storage container.
44
     *
44
     *
45
     * @access public
45
     * @access public
46
     */
46
     */
47
    var $activeUser = "";
47
    var $activeUser = "";
-
 
48
 
-
 
49
    /**
-
 
50
     * The Auth object this container is attached to.
-
 
51
     *
-
 
52
     * @access public
-
 
53
     */
-
 
54
    var $_auth_obj = null;
48
 
55
 
49
    // }}}
56
    // }}}
50
    // {{{ Auth_Container() [constructor]
57
    // {{{ Auth_Container() [constructor]
51
 
58
 
52
    /**
59
    /**
53
     * Constructor
60
     * Constructor
54
     *
61
     *
55
     * Has to be overwritten by each storage class
62
     * Has to be overwritten by each storage class
56
     *
63
     *
57
     * @access public
64
     * @access public
58
     */
65
     */
59
    function Auth_Container()
66
    function Auth_Container()
60
    {
67
    {
61
    }
68
    }
62
 
69
 
63
    // }}}
70
    // }}}
64
    // {{{ fetchData()
71
    // {{{ fetchData()
65
 
72
 
66
    /**
73
    /**
67
     * Fetch data from storage container
74
     * Fetch data from storage container
68
     *
75
     *
69
     * Has to be overwritten by each storage class
76
     * Has to be overwritten by each storage class
70
     *
77
     *
71
     * @access public
78
     * @access public
72
     */
79
     */
73
    function fetchData($username, $password, $isChallengeResponse=false)
80
    function fetchData($username, $password, $isChallengeResponse=false)
74
    {
81
    {
-
 
82
        $this->log('Auth_Container::fetchData() called.', AUTH_LOG_DEBUG);
75
    }
83
    }
76
 
84
 
77
    // }}}
85
    // }}}
78
    // {{{ verifyPassword()
86
    // {{{ verifyPassword()
79
 
87
 
80
    /**
88
    /**
81
     * Crypt and verfiy the entered password
89
     * Crypt and verfiy the entered password
82
     *
90
     *
83
     * @param  string Entered password
91
     * @param  string Entered password
84
     * @param  string Password from the data container (usually this password
92
     * @param  string Password from the data container (usually this password
85
     *                is already encrypted.
93
     *                is already encrypted.
86
     * @param  string Type of algorithm with which the password from
94
     * @param  string Type of algorithm with which the password from
87
     *                the container has been crypted. (md5, crypt etc.)
95
     *                the container has been crypted. (md5, crypt etc.)
88
     *                Defaults to "md5".
96
     *                Defaults to "md5".
89
     * @return bool   True, if the passwords match
97
     * @return bool   True, if the passwords match
90
     */
98
     */
91
    function verifyPassword($password1, $password2, $cryptType = "md5")
99
    function verifyPassword($password1, $password2, $cryptType = "md5")
92
    {
100
    {
-
 
101
        $this->log('Auth_Container::verifyPassword() called.', AUTH_LOG_DEBUG);
93
        switch ($cryptType) {
102
        switch ($cryptType) {
94
            case "crypt" :
103
            case "crypt" :
95
                return ((string)crypt($password1, $password2) === (string)$password2);
104
                return ((string)crypt($password1, $password2) === (string)$password2);
96
                break;
105
                break;
97
            case "none" :
106
            case "none" :
98
            case "" :
107
            case "" :
99
                return ((string)$password1 === (string)$password2);
108
                return ((string)$password1 === (string)$password2);
100
                break;
109
                break;
101
            case "md5" :
110
            case "md5" :
102
                return ((string)md5($password1) === (string)$password2);
111
                return ((string)md5($password1) === (string)$password2);
103
                break;
112
                break;
104
            default :
113
            default :
105
                if (function_exists($cryptType)) {
114
                if (function_exists($cryptType)) {
106
                    return ((string)$cryptType($password1) === (string)$password2);
115
                    return ((string)$cryptType($password1) === (string)$password2);
107
                } elseif (method_exists($this,$cryptType)) { 
116
                } elseif (method_exists($this,$cryptType)) {
108
                    return ((string)$this->$cryptType($password1) === (string)$password2);
117
                    return ((string)$this->$cryptType($password1) === (string)$password2);
109
                } else {
118
                } else {
110
                    return false;
119
                    return false;
111
                }
120
                }
112
                break;
121
                break;
113
        }
122
        }
114
    }
123
    }
115
 
124
 
116
    // }}}
125
    // }}}
117
    // {{{ supportsChallengeResponse()
126
    // {{{ supportsChallengeResponse()
118
    
127
 
119
    /**
128
    /**
120
      * Returns true if the container supports Challenge Response 
129
      * Returns true if the container supports Challenge Response
121
      * password authentication
130
      * password authentication
122
      */
131
      */
123
    function supportsChallengeResponse()
132
    function supportsChallengeResponse()
124
    {
133
    {
125
        return(false);
134
        return(false);
126
    }
135
    }
127
 
136
 
128
    // }}}
137
    // }}}
129
    // {{{ getCryptType()
138
    // {{{ getCryptType()
130
    
139
 
131
    /**
140
    /**
132
      * Returns the crypt current crypt type of the container
141
      * Returns the crypt current crypt type of the container
133
      *
142
      *
134
      * @return string
143
      * @return string
135
      */
144
      */
136
    function getCryptType()
145
    function getCryptType()
137
    {
146
    {
138
        return('');
147
        return('');
139
    }
148
    }
140
 
149
 
141
    // }}}
150
    // }}}
142
    // {{{ listUsers()
151
    // {{{ listUsers()
143
 
152
 
144
    /**
153
    /**
145
     * List all users that are available from the storage container
154
     * List all users that are available from the storage container
146
     */
155
     */
147
    function listUsers()
156
    function listUsers()
148
    {
157
    {
-
 
158
        $this->log('Auth_Container::listUsers() called.', AUTH_LOG_DEBUG);
149
        return AUTH_METHOD_NOT_SUPPORTED;
159
        return AUTH_METHOD_NOT_SUPPORTED;
150
    }
160
    }
151
 
161
 
152
    // }}}
162
    // }}}
153
    // {{{ getUser()
163
    // {{{ getUser()
154
 
164
 
155
    /**
165
    /**
156
     * Returns a user assoc array
166
     * Returns a user assoc array
157
     *
167
     *
158
     * Containers which want should overide this
168
     * Containers which want should overide this
159
     *
169
     *
160
     * @param string The username
170
     * @param string The username
161
     */
171
     */
162
    function getUser($username)
172
    function getUser($username)
163
    {
173
    {
-
 
174
        $this->log('Auth_Container::getUser() called.', AUTH_LOG_DEBUG);
164
        $users = $this->listUsers();
175
        $users = $this->listUsers();
165
        if ($users === AUTH_METHOD_NOT_SUPPORTED) {
176
        if ($users === AUTH_METHOD_NOT_SUPPORTED) {
166
            return AUTH_METHOD_NOT_SUPPORTED;
177
            return AUTH_METHOD_NOT_SUPPORTED;
167
        }
178
        }
168
        for ($i=0; $c = count($users), $i<$c; $i++) {
179
        for ($i=0; $c = count($users), $i<$c; $i++) {
169
            if ($users[$i]['username'] == $username) {
180
            if ($users[$i]['username'] == $username) {
170
                return $users[$i];
181
                return $users[$i];
171
            }
182
            }
172
        }
183
        }
173
        return false;
184
        return false;
174
    }
185
    }
175
 
186
 
176
    // }}}
187
    // }}}
177
    // {{{ addUser()
188
    // {{{ addUser()
178
 
189
 
179
    /**
190
    /**
180
     * Add a new user to the storage container
191
     * Add a new user to the storage container
181
     *
192
     *
182
     * @param string Username
193
     * @param string Username
183
     * @param string Password
194
     * @param string Password
184
     * @param array  Additional information
195
     * @param array  Additional information
185
     *
196
     *
186
     * @return boolean
197
     * @return boolean
187
     */
198
     */
188
    function addUser($username, $password, $additional=null)
199
    function addUser($username, $password, $additional=null)
189
    {
200
    {
-
 
201
        $this->log('Auth_Container::addUser() called.', AUTH_LOG_DEBUG);
190
        return AUTH_METHOD_NOT_SUPPORTED;
202
        return AUTH_METHOD_NOT_SUPPORTED;
191
    }
203
    }
192
 
204
 
193
    // }}}
205
    // }}}
194
    // {{{ removeUser()
206
    // {{{ removeUser()
195
 
207
 
196
    /**
208
    /**
197
     * Remove user from the storage container
209
     * Remove user from the storage container
198
     *
210
     *
199
     * @param string Username
211
     * @param string Username
200
     */
212
     */
201
    function removeUser($username)
213
    function removeUser($username)
202
    {
214
    {
-
 
215
        $this->log('Auth_Container::removeUser() called.', AUTH_LOG_DEBUG);
203
        return AUTH_METHOD_NOT_SUPPORTED;
216
        return AUTH_METHOD_NOT_SUPPORTED;
204
    }
217
    }
205
 
218
 
206
    // }}}
219
    // }}}
207
    // {{{ changePassword()
220
    // {{{ changePassword()
208
 
221
 
209
    /**
222
    /**
210
     * Change password for user in the storage container
223
     * Change password for user in the storage container
211
     *
224
     *
212
     * @param string Username
225
     * @param string Username
213
     * @param string The new password
226
     * @param string The new password
214
     */
227
     */
215
    function changePassword($username, $password)
228
    function changePassword($username, $password)
216
    {
229
    {
-
 
230
        $this->log('Auth_Container::changePassword() called.', AUTH_LOG_DEBUG);
217
        return AUTH_METHOD_NOT_SUPPORTED;
231
        return AUTH_METHOD_NOT_SUPPORTED;
218
    }
232
    }
-
 
233
 
-
 
234
    // }}}
-
 
235
    // {{{ log()
-
 
236
 
-
 
237
    /**
-
 
238
     * Log a message to the Auth log
-
 
239
     *
-
 
240
     * @param string The message
-
 
241
     * @param int
-
 
242
     * @return boolean
-
 
243
     */
-
 
244
    function log($message, $level = AUTH_LOG_DEBUG) {
-
 
245
 
-
 
246
        if (is_null($this->_auth_obj)) {
-
 
247
 
-
 
248
            return false;
-
 
249
 
-
 
250
        } else {
-
 
251
 
-
 
252
            return $this->_auth_obj->log($message, $level);
-
 
253
 
-
 
254
        }
-
 
255
 
-
 
256
    }
219
 
257
 
220
    // }}}
258
    // }}}
221
 
259
 
222
}
260
}
223
 
261
 
224
?>
262
?>