Subversion Repositories Applications.papyrus

Rev

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

Rev 1713 Rev 2150
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.3 2007-11-19 15:11:00 jp_milcent Exp $
21
 * @version    CVS: $Id: Container.php,v 1.28 2007/06/12 03:11:26 aashley 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.5.4  File: $Revision: 1.3 $
34
 * @version    Release: 1.5.4  File: $Revision: 1.28 $
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
 
48
 
49
    /**
49
    /**
50
     * The Auth object this container is attached to.
50
     * The Auth object this container is attached to.
51
     *
51
     *
52
     * @access public
52
     * @access public
53
     */
53
     */
54
    var $_auth_obj = null;
54
    var $_auth_obj = null;
55
 
55
 
56
    // }}}
56
    // }}}
57
    // {{{ Auth_Container() [constructor]
57
    // {{{ Auth_Container() [constructor]
58
 
58
 
59
    /**
59
    /**
60
     * Constructor
60
     * Constructor
61
     *
61
     *
62
     * Has to be overwritten by each storage class
62
     * Has to be overwritten by each storage class
63
     *
63
     *
64
     * @access public
64
     * @access public
65
     */
65
     */
66
    function Auth_Container()
66
    function Auth_Container()
67
    {
67
    {
68
    }
68
    }
69
 
69
 
70
    // }}}
70
    // }}}
71
    // {{{ fetchData()
71
    // {{{ fetchData()
72
 
72
 
73
    /**
73
    /**
74
     * Fetch data from storage container
74
     * Fetch data from storage container
75
     *
75
     *
76
     * Has to be overwritten by each storage class
76
     * Has to be overwritten by each storage class
77
     *
77
     *
78
     * @access public
78
     * @access public
79
     */
79
     */
80
    function fetchData($username, $password, $isChallengeResponse=false)
80
    function fetchData($username, $password, $isChallengeResponse=false)
81
    {
81
    {
82
        $this->log('Auth_Container::fetchData() called.', AUTH_LOG_DEBUG);
82
        $this->log('Auth_Container::fetchData() called.', AUTH_LOG_DEBUG);
83
    }
83
    }
84
 
84
 
85
    // }}}
85
    // }}}
86
    // {{{ verifyPassword()
86
    // {{{ verifyPassword()
87
 
87
 
88
    /**
88
    /**
89
     * Crypt and verfiy the entered password
89
     * Crypt and verfiy the entered password
90
     *
90
     *
91
     * @param  string Entered password
91
     * @param  string Entered password
92
     * @param  string Password from the data container (usually this password
92
     * @param  string Password from the data container (usually this password
93
     *                is already encrypted.
93
     *                is already encrypted.
94
     * @param  string Type of algorithm with which the password from
94
     * @param  string Type of algorithm with which the password from
95
     *                the container has been crypted. (md5, crypt etc.)
95
     *                the container has been crypted. (md5, crypt etc.)
96
     *                Defaults to "md5".
96
     *                Defaults to "md5".
97
     * @return bool   True, if the passwords match
97
     * @return bool   True, if the passwords match
98
     */
98
     */
99
    function verifyPassword($password1, $password2, $cryptType = "md5")
99
    function verifyPassword($password1, $password2, $cryptType = "md5")
100
    {
100
    {
101
        $this->log('Auth_Container::verifyPassword() called.', AUTH_LOG_DEBUG);
101
        $this->log('Auth_Container::verifyPassword() called.', AUTH_LOG_DEBUG);
102
        switch ($cryptType) {
102
        switch ($cryptType) {
103
            case "crypt" :
103
            case "crypt" :
104
                return ((string)crypt($password1, $password2) === (string)$password2);
104
                return ((string)crypt($password1, $password2) === (string)$password2);
105
                break;
105
                break;
106
            case "none" :
106
            case "none" :
107
            case "" :
107
            case "" :
108
                return ((string)$password1 === (string)$password2);
108
                return ((string)$password1 === (string)$password2);
109
                break;
109
                break;
110
            case "md5" :
110
            case "md5" :
111
                return ((string)md5($password1) === (string)$password2);
111
                return ((string)md5($password1) === (string)$password2);
112
                break;
112
                break;
113
            default :
113
            default :
114
                if (function_exists($cryptType)) {
114
                if (function_exists($cryptType)) {
115
                    return ((string)$cryptType($password1) === (string)$password2);
115
                    return ((string)$cryptType($password1) === (string)$password2);
116
                } elseif (method_exists($this,$cryptType)) {
116
                } elseif (method_exists($this,$cryptType)) {
117
                    return ((string)$this->$cryptType($password1) === (string)$password2);
117
                    return ((string)$this->$cryptType($password1) === (string)$password2);
118
                } else {
118
                } else {
119
                    return false;
119
                    return false;
120
                }
120
                }
121
                break;
121
                break;
122
        }
122
        }
123
    }
123
    }
124
 
124
 
125
    // }}}
125
    // }}}
126
    // {{{ supportsChallengeResponse()
126
    // {{{ supportsChallengeResponse()
127
 
127
 
128
    /**
128
    /**
129
      * Returns true if the container supports Challenge Response
129
      * Returns true if the container supports Challenge Response
130
      * password authentication
130
      * password authentication
131
      */
131
      */
132
    function supportsChallengeResponse()
132
    function supportsChallengeResponse()
133
    {
133
    {
134
        return(false);
134
        return(false);
135
    }
135
    }
136
 
136
 
137
    // }}}
137
    // }}}
138
    // {{{ getCryptType()
138
    // {{{ getCryptType()
139
 
139
 
140
    /**
140
    /**
141
      * Returns the crypt current crypt type of the container
141
      * Returns the crypt current crypt type of the container
142
      *
142
      *
143
      * @return string
143
      * @return string
144
      */
144
      */
145
    function getCryptType()
145
    function getCryptType()
146
    {
146
    {
147
        return('');
147
        return('');
148
    }
148
    }
149
 
149
 
150
    // }}}
150
    // }}}
151
    // {{{ listUsers()
151
    // {{{ listUsers()
152
 
152
 
153
    /**
153
    /**
154
     * List all users that are available from the storage container
154
     * List all users that are available from the storage container
155
     */
155
     */
156
    function listUsers()
156
    function listUsers()
157
    {
157
    {
158
        $this->log('Auth_Container::listUsers() called.', AUTH_LOG_DEBUG);
158
        $this->log('Auth_Container::listUsers() called.', AUTH_LOG_DEBUG);
159
        return AUTH_METHOD_NOT_SUPPORTED;
159
        return AUTH_METHOD_NOT_SUPPORTED;
160
    }
160
    }
161
 
161
 
162
    // }}}
162
    // }}}
163
    // {{{ getUser()
163
    // {{{ getUser()
164
 
164
 
165
    /**
165
    /**
166
     * Returns a user assoc array
166
     * Returns a user assoc array
167
     *
167
     *
168
     * Containers which want should overide this
168
     * Containers which want should overide this
169
     *
169
     *
170
     * @param string The username
170
     * @param string The username
171
     */
171
     */
172
    function getUser($username)
172
    function getUser($username)
173
    {
173
    {
174
        $this->log('Auth_Container::getUser() called.', AUTH_LOG_DEBUG);
174
        $this->log('Auth_Container::getUser() called.', AUTH_LOG_DEBUG);
175
        $users = $this->listUsers();
175
        $users = $this->listUsers();
176
        if ($users === AUTH_METHOD_NOT_SUPPORTED) {
176
        if ($users === AUTH_METHOD_NOT_SUPPORTED) {
177
            return AUTH_METHOD_NOT_SUPPORTED;
177
            return AUTH_METHOD_NOT_SUPPORTED;
178
        }
178
        }
179
        for ($i=0; $c = count($users), $i<$c; $i++) {
179
        for ($i=0; $c = count($users), $i<$c; $i++) {
180
            if ($users[$i]['username'] == $username) {
180
            if ($users[$i]['username'] == $username) {
181
                return $users[$i];
181
                return $users[$i];
182
            }
182
            }
183
        }
183
        }
184
        return false;
184
        return false;
185
    }
185
    }
186
 
186
 
187
    // }}}
187
    // }}}
188
    // {{{ addUser()
188
    // {{{ addUser()
189
 
189
 
190
    /**
190
    /**
191
     * Add a new user to the storage container
191
     * Add a new user to the storage container
192
     *
192
     *
193
     * @param string Username
193
     * @param string Username
194
     * @param string Password
194
     * @param string Password
195
     * @param array  Additional information
195
     * @param array  Additional information
196
     *
196
     *
197
     * @return boolean
197
     * @return boolean
198
     */
198
     */
199
    function addUser($username, $password, $additional=null)
199
    function addUser($username, $password, $additional=null)
200
    {
200
    {
201
        $this->log('Auth_Container::addUser() called.', AUTH_LOG_DEBUG);
201
        $this->log('Auth_Container::addUser() called.', AUTH_LOG_DEBUG);
202
        return AUTH_METHOD_NOT_SUPPORTED;
202
        return AUTH_METHOD_NOT_SUPPORTED;
203
    }
203
    }
204
 
204
 
205
    // }}}
205
    // }}}
206
    // {{{ removeUser()
206
    // {{{ removeUser()
207
 
207
 
208
    /**
208
    /**
209
     * Remove user from the storage container
209
     * Remove user from the storage container
210
     *
210
     *
211
     * @param string Username
211
     * @param string Username
212
     */
212
     */
213
    function removeUser($username)
213
    function removeUser($username)
214
    {
214
    {
215
        $this->log('Auth_Container::removeUser() called.', AUTH_LOG_DEBUG);
215
        $this->log('Auth_Container::removeUser() called.', AUTH_LOG_DEBUG);
216
        return AUTH_METHOD_NOT_SUPPORTED;
216
        return AUTH_METHOD_NOT_SUPPORTED;
217
    }
217
    }
218
 
218
 
219
    // }}}
219
    // }}}
220
    // {{{ changePassword()
220
    // {{{ changePassword()
221
 
221
 
222
    /**
222
    /**
223
     * Change password for user in the storage container
223
     * Change password for user in the storage container
224
     *
224
     *
225
     * @param string Username
225
     * @param string Username
226
     * @param string The new password
226
     * @param string The new password
227
     */
227
     */
228
    function changePassword($username, $password)
228
    function changePassword($username, $password)
229
    {
229
    {
230
        $this->log('Auth_Container::changePassword() called.', AUTH_LOG_DEBUG);
230
        $this->log('Auth_Container::changePassword() called.', AUTH_LOG_DEBUG);
231
        return AUTH_METHOD_NOT_SUPPORTED;
231
        return AUTH_METHOD_NOT_SUPPORTED;
232
    }
232
    }
233
 
233
 
234
    // }}}
234
    // }}}
235
    // {{{ log()
235
    // {{{ log()
236
 
236
 
237
    /**
237
    /**
238
     * Log a message to the Auth log
238
     * Log a message to the Auth log
239
     *
239
     *
240
     * @param string The message
240
     * @param string The message
241
     * @param int
241
     * @param int
242
     * @return boolean
242
     * @return boolean
243
     */
243
     */
244
    function log($message, $level = AUTH_LOG_DEBUG) {
244
    function log($message, $level = AUTH_LOG_DEBUG) {
245
 
245
 
246
        if (is_null($this->_auth_obj)) {
246
        if (is_null($this->_auth_obj)) {
247
 
247
 
248
            return false;
248
            return false;
249
 
249
 
250
        } else {
250
        } else {
251
 
251
 
252
            return $this->_auth_obj->log($message, $level);
252
            return $this->_auth_obj->log($message, $level);
253
 
253
 
254
        }
254
        }
255
 
255
 
256
    }
256
    }
257
 
257
 
258
    // }}}
258
    // }}}
259
 
259
 
260
}
260
}
261
 
261
 
262
?>
262
?>