Subversion Repositories Applications.papyrus

Rev

Rev 320 | Rev 1713 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 320 Rev 1173
Line 1... Line -...
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.1 2005-03-30 08:50:19 jpm Exp $
-
 
20
//
-
 
21
 
-
 
22
require_once 'PEAR.php';
-
 
23
 
-
 
24
define('AUTH_IDLED',       -1);
-
 
25
define('AUTH_EXPIRED',     -2);
-
 
26
define('AUTH_WRONG_LOGIN', -3);
-
 
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.1 $
-
 
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(), drawLogin()
-
 
55
     */
-
 
56
    var $expired = false;
-
 
57
 
-
 
58
    /**
-
 
59
     * Maximum time of idleness 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, idle time 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(), drawLogin();
-
 
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
     * Function defined by the user, 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
     * Current authentication status
-
 
103
     *
-
 
104
     * @var string
-
 
105
     */
-
 
106
    var $status = '';
-
 
107
 
-
 
108
    /**
-
 
109
     * Username
-
 
110
     *
-
 
111
     * @var string
-
 
112
     */
-
 
113
    var $username = '';
-
 
114
 
-
 
115
    /**
-
 
116
     * Password
-
 
117
     *
-
 
118
     * @var string
-
 
119
     */
-
 
120
    var $password = '';
-
 
121
 
-
 
122
    /**
-
 
123
     * Login callback function name
-
 
124
     *
-
 
125
     * @var string
-
 
126
     * @see setLoginCallback()
-
 
127
     */
-
 
128
    var $loginCallback = '';
-
 
129
 
-
 
130
    /**
-
 
131
     * Failed Login callback function name
-
 
132
     *
-
 
133
     * @var string
-
 
134
     * @see setLoginFailedCallback()
-
 
135
     */
-
 
136
    var $loginFailedCallback = '';
-
 
137
 
-
 
138
    /**
-
 
139
     * Logout callback function name
-
 
140
     *
-
 
141
     * @var string
-
 
142
     * @see setLogoutCallback()
-
 
143
     */
-
 
144
    var $logoutCallback = '';
-
 
145
 
-
 
146
    /**
-
 
147
     * Auth session-array name
-
 
148
     *
-
 
149
     * @var string
-
 
150
     */
-
 
151
    var $_sessionName = '_authsession';
-
 
152
    
-
 
153
    /**
-
 
154
     * Package Version
-
 
155
     *
-
 
156
     * @var string
-
 
157
     */
-
 
158
    var $version = "1.2.3";
-
 
159
 
-
 
160
    // {{{ Constructor
-
 
161
 
-
 
162
    /**
-
 
163
     * Constructor
-
 
164
     *
-
 
165
     * Set up the storage driver.
-
 
166
     *
-
 
167
     * @param string    Type of the storage driver
-
 
168
     * @param mixed     Additional options for the storage driver
-
 
169
     *                  (example: if you are using DB as the storage
-
 
170
     *                   driver, you have to pass the dsn string here)
-
 
171
     *
-
 
172
     * @param string    Name of the function that creates the login form
-
 
173
     * @param boolean   Should the login form be displayed if neccessary?
-
 
174
     * @return void
-
 
175
     */
-
 
176
    function Auth($storageDriver, $options = '', $loginFunction = '', $showLogin = true)
-
 
177
    {
-
 
178
        if (!empty($options['sessionName'])) {
-
 
179
            $this->_sessionName = $options['sessionName'];
-
 
180
            unset($options['sessionName']);
-
 
181
        }
-
 
182
 
-
 
183
        if ($loginFunction != '' && is_callable($loginFunction)) {
-
 
184
            $this->loginFunction = $loginFunction;
-
 
185
        }
-
 
186
 
-
 
187
        if (is_bool($showLogin)) {
-
 
188
            $this->showLogin = $showLogin;
-
 
189
        }
-
 
190
 
-
 
191
        if (is_object($storageDriver)) {
-
 
192
            $this->storage =& $storageDriver;
-
 
193
        } else {
-
 
194
            $this->storage = $this->_factory($storageDriver, $options);
-
 
195
        }
-
 
196
        // Pass a reference to auth to the container, ugly but works
-
 
197
        // this is used by the DB container to use method setAuthData not staticaly.
-
 
198
        $this->storage->_auth_obj =& $this;
-
 
199
    }
-
 
200
 
-
 
201
    // }}}
-
 
202
    // {{{ _factory()
-
 
203
 
-
 
204
    /**
-
 
205
     * Return a storage driver based on $driver and $options
-
 
206
     *
-
 
207
     * @access private
-
 
208
     * @static
-
 
209
     * @param  string $driver  Type of storage class to return
-
 
210
     * @param  string $options Optional parameters for the storage class
-
 
211
     * @return object Object   Storage object
-
 
212
     */
-
 
213
    function _factory($driver, $options = '')
-
 
214
    {
-
 
215
        $storage_path = 'Auth/Container/' . $driver . '.php';
-
 
216
        $storage_class = 'Auth_Container_' . $driver;
-
 
217
 
-
 
218
        require_once $storage_path;
-
 
219
 
-
 
220
        return new $storage_class($options);
-
 
221
    }
-
 
222
 
-
 
223
    // }}}
-
 
224
    // {{{ assignData()
-
 
225
 
-
 
226
    /**
-
 
227
     * Assign data from login form to internal values
-
 
228
     *
-
 
229
     * This function takes the values for username and password
-
 
230
     * from $HTTP_POST_VARS and assigns them to internal variables.
-
 
231
     * If you wish to use another source apart from $HTTP_POST_VARS,
-
 
232
     * you have to derive this function.
-
 
233
     *
-
 
234
     * @access private
-
 
235
     * @global $HTTP_POST_VARS
-
 
236
     * @see    Auth
-
 
237
     * @return void
-
 
238
     */
-
 
239
    function assignData()
-
 
240
    {
-
 
241
        $post = &$this->_importGlobalVariable('post');
-
 
242
 
-
 
243
        if (isset($post['username']) && $post['username'] != '') {
-
 
244
            $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($post['username']) : $post['username']);
-
 
245
        }
-
 
246
 
-
 
247
        if (isset($post['password']) && $post['password'] != '') {
-
 
248
            $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($post['password']) : $post['password'] );
-
 
249
        }
-
 
250
 
-
 
251
    }
-
 
252
 
-
 
253
    // }}}
-
 
254
    // {{{ start()
-
 
255
 
-
 
256
    /**
-
 
257
     * Start new auth session
-
 
258
     *
-
 
259
     * @access public
-
 
260
     * @return void
-
 
261
     */
-
 
262
    function start()
-
 
263
    {
-
 
264
        $this->assignData();
-
 
265
 
-
 
266
        @session_start();
-
 
267
 
-
 
268
        if (!$this->checkAuth()) {
-
 
269
            $this->login();
-
 
270
        }
-
 
271
    }
-
 
272
 
-
 
273
    // }}}
-
 
274
    // {{{ login()
-
 
275
 
-
 
276
    /**
-
 
277
     * Login function
-
 
278
     *
-
 
279
     * @access private
-
 
280
     * @return void
-
 
281
     */
-
 
282
    function login()
-
 
283
    {
-
 
284
        $login_ok = false;
-
 
285
 
-
 
286
        /**
-
 
287
         * When the user has already entered a username,
-
 
288
         * we have to validate it.
-
 
289
         */
-
 
290
        if (!empty($this->username)) {
-
 
291
            if (true === $this->storage->fetchData($this->username, $this->password)) {
-
 
292
                $login_ok = true;
-
 
293
            } else {
-
 
294
                if (is_callable($this->loginFailedCallback)) {
-
 
295
                    call_user_func($this->loginFailedCallback,$this->username, $this);
-
 
296
                }
-
 
297
            }
-
 
298
        }
-
 
299
 
-
 
300
        if (!empty($this->username) && $login_ok) {
-
 
301
            $this->setAuth($this->username);
-
 
302
            if (is_callable($this->loginCallback)) {
-
 
303
                call_user_func($this->loginCallback,$this->username, $this);
-
 
304
            }
-
 
305
        }
-
 
306
 
-
 
307
        /**
-
 
308
         * If the login failed or the user entered no username,
-
 
309
         * output the login screen again.
-
 
310
         */
-
 
311
        if (!empty($this->username) && !$login_ok) {
-
 
312
            $this->status = AUTH_WRONG_LOGIN;
-
 
313
        }
-
 
314
 
-
 
315
        if ((empty($this->username) || !$login_ok) && $this->showLogin) {
-
 
316
            $this->drawLogin($this->storage->activeUser);
-
 
317
            return;
-
 
318
        }
-
 
319
    }
-
 
320
 
-
 
321
    // }}}
-
 
322
    // {{{ setExpire()
-
 
323
 
-
 
324
    /**
-
 
325
     * Set the maximum expire time
-
 
326
     *
-
 
327
     * @access public
-
 
328
     * @param  integer time in seconds
-
 
329
     * @param  bool    add time to current expire time or not
-
 
330
     * @return void
-
 
331
     */
-
 
332
    function setExpire($time, $add = false)
-
 
333
    {
-
 
334
        if ($add) {
-
 
335
            $this->expire += $time;
-
 
336
        } else {
-
 
337
            $this->expire = $time;
-
 
338
        }
-
 
339
    }
-
 
340
 
-
 
341
    // }}}
-
 
342
    // {{{ setIdle()
-
 
343
 
-
 
344
    /**
-
 
345
     * Set the maximum idle time
-
 
346
     *
-
 
347
     * @access public
-
 
348
     * @param  integer time in seconds
-
 
349
     * @param  bool    add time to current maximum idle time or not
-
 
350
     * @return void
-
 
351
     */
-
 
352
    function setIdle($time, $add = false)
-
 
353
    {
-
 
354
        if ($add) {
-
 
355
            $this->idle += $time;
-
 
356
        } else {
-
 
357
            $this->idle = $time;
-
 
358
        }
-
 
359
    }
-
 
360
 
-
 
361
    // }}}
-
 
362
    // {{{ setSessionname()
-
 
363
 
-
 
364
    /**
-
 
365
     * Set name of the session to a customized value.
-
 
366
     *
-
 
367
     * If you are using multiple instances of PEAR::Auth
-
 
368
     * on the same domain, you can change the name of
-
 
369
     * session per application via this function.
-
 
370
     *
-
 
371
     * @access public
-
 
372
     * @param  string New name for the session
-
 
373
     * @return void
-
 
374
     */
-
 
375
    function setSessionname($name = 'PHPSESSID')
-
 
376
    {
-
 
377
        @session_name($name);
-
 
378
    }
-
 
379
 
-
 
380
    // }}}
-
 
381
    // {{{ setShowLogin()
-
 
382
 
-
 
383
    /**
-
 
384
     * Should the login form be displayed if neccessary?
-
 
385
     *
-
 
386
     * @access public
-
 
387
     * @param  bool    show login form or not
-
 
388
     * @return void
-
 
389
     */
-
 
390
    function setShowLogin($showLogin = true)
-
 
391
    {
-
 
392
        $this->showLogin = $showLogin;
-
 
393
    }
-
 
394
 
-
 
395
    /**
-
 
396
     * Register a callback function to be called on user login.
-
 
397
     * The function will receive two parameters, the username and a reference to the auth object.
-
 
398
     *
-
 
399
     * @access public
-
 
400
     * @param  string  callback function name
-
 
401
     * @return void
-
 
402
     * @see    setLogoutCallback()
-
 
403
     */
-
 
404
    function setLoginCallback($loginCallback)
-
 
405
    {
-
 
406
        $this->loginCallback = $loginCallback;
-
 
407
    }
-
 
408
 
-
 
409
    /**
-
 
410
     * Register a callback function to be called on failed user login.
-
 
411
     * The function will receive a single parameter, the username and a reference to the auth object.
-
 
412
     *
-
 
413
     * @access public
-
 
414
     * @param  string  callback function name
-
 
415
     * @return void
-
 
416
     */
-
 
417
    function setFailedLoginCallback($loginFailedCallback)
-
 
418
    {
-
 
419
        $this->loginFailedCallback = $loginFailedCallback;
-
 
420
    }
-
 
421
 
-
 
422
    /**
-
 
423
     * Register a callback function to be called on user logout.
-
 
424
     * The function will receive three parameters, the username and a reference to the auth object.
-
 
425
     *
-
 
426
     * @access public
-
 
427
     * @param  string  callback function name
-
 
428
     * @return void
-
 
429
     * @see    setLoginCallback()
-
 
430
     */
-
 
431
    function setLogoutCallback($logoutCallback)
-
 
432
    {
-
 
433
        $this->logoutCallback = $logoutCallback;
-
 
434
    }
-
 
435
 
-
 
436
    // }}}
-
 
437
    // {{{ setAuthData()
-
 
438
 
-
 
439
    /**
-
 
440
     * Register additional information that is to be stored
-
 
441
     * in the session.
-
 
442
     *
-
 
443
     * @access public
-
 
444
     * @param  string  Name of the data field
-
 
445
     * @param  mixed   Value of the data field
-
 
446
     * @param  boolean Should existing data be overwritten? (default
-
 
447
     *                 is true)
-
 
448
     * @return void
-
 
449
     */
-
 
450
    function setAuthData($name, $value, $overwrite = true)
-
 
451
    {
-
 
452
        $session = &Auth::_importGlobalVariable('session');
-
 
453
 
-
 
454
        if (!empty($session[$this->_sessionName]['data'][$name]) && $overwrite == false) {
-
 
455
            return;
-
 
456
        }
-
 
457
        $session[$this->_sessionName]['data'][$name] = $value;
-
 
458
    }
-
 
459
 
-
 
460
    // }}}
-
 
461
    // {{{ getAuthData()
-
 
462
 
-
 
463
    /**
-
 
464
     * Get additional information that is stored in the session.
-
 
465
     *
-
 
466
     * If no value for the first parameter is passed, the method will
-
 
467
     * return all data that is currently stored.
-
 
468
     *
-
 
469
     * @access public
-
 
470
     * @param  string Name of the data field
-
 
471
     * @return mixed  Value of the data field.
-
 
472
     */
-
 
473
    function getAuthData($name = null)
-
 
474
    {
-
 
475
        $session = &Auth::_importGlobalVariable('session');
-
 
476
        if(!isset($session[$this->_sessionName]['data'])){
-
 
477
            return(null);
-
 
478
        }
-
 
479
 
-
 
480
        if (is_null($name)) {
-
 
481
            if(isset($session[$this->_sessionName]['data'])) {
-
 
482
                return $session[$this->_sessionName]['data'];
-
 
483
            } else {
-
 
484
                return null;
-
 
485
            }
-
 
486
        }
-
 
487
        if (isset($session[$this->_sessionName]['data'][$name])) {
-
 
488
            return $session[$this->_sessionName]['data'][$name];
-
 
489
        } else {
-
 
490
            return null;
-
 
491
        }
-
 
492
    }
-
 
493
 
-
 
494
    // }}}
-
 
495
    // {{{ setAuth()
-
 
496
 
-
 
497
    /**
-
 
498
     * Register variable in a session telling that the user
-
 
499
     * has logged in successfully
-
 
500
     *
-
 
501
     * @access public
-
 
502
     * @param  string Username
-
 
503
     * @return void
-
 
504
     */
-
 
505
    function setAuth($username)
-
 
506
    {
-
 
507
        $session = &Auth::_importGlobalVariable('session');
-
 
508
 
-
 
509
        if (!isset($session[$this->_sessionName]) && !isset($_SESSION)) {
-
 
510
            session_register($this->_sessionName);
-
 
511
        }
-
 
512
 
-
 
513
        if (!isset($session[$this->_sessionName]) || !is_array($session[$this->_sessionName])) {
-
 
514
            $session[$this->_sessionName] = array();
-
 
515
        }
-
 
516
 
-
 
517
        if(!isset($session[$this->_sessionName]['data'])){
-
 
518
            $session[$this->_sessionName]['data']       = array();
-
 
519
        }
-
 
520
        $session[$this->_sessionName]['registered'] = true;
-
 
521
        $session[$this->_sessionName]['username']   = $username;
-
 
522
        $session[$this->_sessionName]['timestamp']  = time();
-
 
523
        $session[$this->_sessionName]['idle']       = time();
-
 
524
    }
-
 
525
 
-
 
526
    // }}}
-
 
527
    // {{{ checkAuth()
-
 
528
 
-
 
529
    /**
-
 
530
     * Checks if there is a session with valid auth information.
-
 
531
     *
-
 
532
     * @access private
-
 
533
     * @return boolean  Whether or not the user is authenticated.
-
 
534
     */
-
 
535
    function checkAuth()
-
 
536
    {
-
 
537
        $session = &$this->_importGlobalVariable('session');
-
 
538
 
-
 
539
        if (isset($session[$this->_sessionName])) {
-
 
540
            // Check if authentication session is expired
-
 
541
            if ($this->expire > 0 &&
-
 
542
                isset($session[$this->_sessionName]['timestamp']) &&
-
 
543
                ($session[$this->_sessionName]['timestamp'] + $this->expire) < time()) {
-
 
544
 
-
 
545
                $this->logout();
-
 
546
                $this->expired = true;
-
 
547
                $this->status = AUTH_EXPIRED;
-
 
548
 
-
 
549
                return false;
-
 
550
            }
-
 
551
 
-
 
552
            // Check if maximum idle time is reached
-
 
553
            if ($this->idle > 0 &&
-
 
554
                isset($session[$this->_sessionName]['idle']) &&
-
 
555
                ($session[$this->_sessionName]['idle'] + $this->idle) < time()) {
-
 
556
 
-
 
557
                $this->logout();
-
 
558
                $this->idled = true;
-
 
559
                $this->status = AUTH_IDLED;
-
 
560
 
-
 
561
                return false;
-
 
562
            }
-
 
563
 
-
 
564
            if (isset($session[$this->_sessionName]['registered']) &&
-
 
565
                isset($session[$this->_sessionName]['username']) &&
-
 
566
                $session[$this->_sessionName]['registered'] == true &&
-
 
567
                $session[$this->_sessionName]['username'] != '') {
-
 
568
 
-
 
569
                Auth::updateIdle();
-
 
570
 
-
 
571
                return true;
-
 
572
            }
-
 
573
        }
-
 
574
 
-
 
575
        return false;
-
 
576
    }
-
 
577
 
-
 
578
    // }}}
-
 
579
    // {{{ getAuth()
-
 
580
 
-
 
581
    /**
-
 
582
     * Has the user been authenticated?
-
 
583
     *
-
 
584
     * @access public
-
 
585
     * @return bool  True if the user is logged in, otherwise false.
-
 
586
     */
-
 
587
    function getAuth()
-
 
588
    {
-
 
589
        $session = &$this->_importGlobalVariable('session');
-
 
590
 
-
 
591
        if (!empty($session) &&
-
 
592
            (isset($session[$this->_sessionName]['registered']) &&
-
 
593
             $session[$this->_sessionName]['registered'] === true))
-
 
594
        {
-
 
595
            return true;
-
 
596
        } else {
-
 
597
            return false;
-
 
598
        }
-
 
599
    }
-
 
600
 
-
 
601
    // }}}
-
 
602
    // {{{ drawLogin()
-
 
603
 
-
 
604
    /**
-
 
605
     * Draw the login form
-
 
606
     *
-
 
607
     * Normally you will not use this output in your application,
-
 
608
     * because you can pass a different function name to the
-
 
609
     * constructor. For more information on this, please
-
 
610
     * consult the documentation.
-
 
611
     *
-
 
612
     * @access private
-
 
613
     * @param  string  Username if already entered
-
 
614
     * @return void
-
 
615
     */
-
 
616
    function drawLogin($username = '')
-
 
617
    {
-
 
618
        if (is_callable($this->loginFunction)) {
-
 
619
            call_user_func($this->loginFunction, $username, $this->status, $this);
-
 
620
        } else {
-
 
621
            $server = &$this->_importGlobalVariable('server');
-
 
622
 
-
 
623
            echo '<center>'."\n";
-
 
624
 
-
 
625
            if (!empty($this->status) && $this->status == AUTH_EXPIRED) {
-
 
626
                echo '<i>Your session expired. Please login again!</i>'."\n";
-
 
627
            } else if (!empty($this->status) && $this->status == AUTH_IDLED) {
-
 
628
                echo '<i>You have been idle for too long. Please login again!</i>'."\n";
-
 
629
            } else if (!empty ($this->status) && $this->status == AUTH_WRONG_LOGIN) {
-
 
630
                echo '<i>Wrong login data!</i>'."\n";
-
 
631
            }
-
 
632
 
-
 
633
            PEAR::raiseError('You are using the built-in login screen of PEAR::Auth.<br />See the <a href="http://pear.php.net/manual/">manual</a> for details on how to create your own login function.', null);
-
 
634
 
-
 
635
            echo '<form method="post" action="' . $server['PHP_SELF'] . '">'."\n";
-
 
636
            echo '<table border="0" cellpadding="2" cellspacing="0" summary="login form">'."\n";
-
 
637
            echo '<tr>'."\n";
-
 
638
            echo '    <td colspan="2" bgcolor="#eeeeee"><b>Login:</b></td>'."\n";
-
 
639
            echo '</tr>'."\n";
-
 
640
            echo '<tr>'."\n";
-
 
641
            echo '    <td>Username:</td>'."\n";
-
 
642
            echo '    <td><input type="text" name="username" value="' . $username . '" /></td>'."\n";
-
 
643
            echo '</tr>'."\n";
-
 
644
            echo '<tr>'."\n";
-
 
645
            echo '    <td>Password:</td>'."\n";
-
 
646
            echo '    <td><input type="password" name="password" /></td>'."\n";
-
 
647
            echo '</tr>'."\n";
-
 
648
            echo '<tr>'."\n";
-
 
649
            echo '    <td colspan="2" bgcolor="#eeeeee"><input type="submit" /></td>'."\n";
-
 
650
            echo '</tr>'."\n";
-
 
651
            echo '</table>'."\n";
-
 
652
            echo '</form>'."\n";
-
 
653
            echo '</center>'."\n\n";
-
 
654
        }
-
 
655
    }
-
 
656
 
-
 
657
    // }}}
-
 
658
    // {{{ logout()
-
 
659
 
-
 
660
    /**
-
 
661
     * Logout function
-
 
662
     *
-
 
663
     * This function clears any auth tokens in the currently
-
 
664
     * active session and executes the logout callback function,
-
 
665
     * if any
-
 
666
     *
-
 
667
     * @access public
-
 
668
     * @return void
-
 
669
     */
-
 
670
    function logout()
-
 
671
    {
-
 
672
        $session = &$this->_importGlobalVariable('session');
-
 
673
 
-
 
674
        if (is_callable($this->logoutCallback)) {
-
 
675
            call_user_func($this->logoutCallback, $session[$this->_sessionName]['username'], $this);
-
 
676
        }
-
 
677
 
-
 
678
        $this->username = '';
-
 
679
        $this->password = '';
-
 
680
 
-
 
681
        $session[$this->_sessionName] = array();
-
 
682
        if (isset($_SESSION)) {
-
 
683
            unset($session[$this->_sessionName]);
-
 
684
        } else {
-
 
685
            session_unregister($this->_sessionName);
-
 
686
        }
-
 
687
    }
-
 
688
 
-
 
689
    // }}}
-
 
690
    // {{{ updateIdle()
-
 
691
 
-
 
692
    /**
-
 
693
     * Update the idletime
-
 
694
     *
-
 
695
     * @access private
-
 
696
     * @return void
-
 
697
     */
-
 
698
    function updateIdle()
-
 
699
    {
-
 
700
        $session = &$this->_importGlobalVariable('session');
-
 
701
       $session[$this->_sessionName]['idle'] = time();
-
 
702
    }
-
 
703
 
-
 
704
    // }}}
-
 
705
    // {{{ getUsername()
-
 
706
 
-
 
707
    /**
-
 
708
     * Get the username
-
 
709
     *
-
 
710
     * @access public
-
 
711
     * @return string
-
 
712
     */
-
 
713
    function getUsername()
-
 
714
    {
-
 
715
        $session = &$this->_importGlobalVariable('session');
-
 
716
        if (!isset($session[$this->_sessionName]['username'])) {
-
 
717
            return '';
-
 
718
        }
-
 
719
        return $session[$this->_sessionName]['username'];
-
 
720
    }
-
 
721
 
-
 
722
    // }}}
-
 
723
    // {{{ getStatus()
-
 
724
 
-
 
725
    /**
-
 
726
     * Get the current status
-
 
727
     *
-
 
728
     * @access public
-
 
729
     * @return string
-
 
730
     */
-
 
731
    function getStatus()
-
 
732
    {
-
 
733
        return $this->status;
-
 
734
    }
-
 
735
 
-
 
736
    // }}}
-
 
737
    // {{{ sessionValidThru()
-
 
738
 
-
 
739
    /**
-
 
740
     * Returns the time up to the session is valid
-
 
741
     *
-
 
742
     * @access public
-
 
743
     * @return integer
-
 
744
     */
-
 
745
    function sessionValidThru()
-
 
746
    {
-
 
747
        $session = &$this->_importGlobalVariable('session');
-
 
748
        if (!isset($session[$this->_sessionName]['idle'])) {
-
 
749
            return 0;
-
 
750
        }
-
 
751
        return ($session[$this->_sessionName]['idle'] + $this->idle);
-
 
752
    }
-
 
753
 
-
 
754
    // }}}
-
 
755
    // {{{ listUsers()
-
 
756
 
-
 
757
    /**
-
 
758
     * List all users that are currently available in the storage
-
 
759
     * container
-
 
760
     *
-
 
761
     * @access public
-
 
762
     * @return array
-
 
763
     */
-
 
764
    function listUsers()
-
 
765
    {
-
 
766
        return $this->storage->listUsers();
-
 
767
    }
-
 
768
 
-
 
769
    // }}}
-
 
770
    // {{{ addUser()
-
 
771
 
-
 
772
    /**
-
 
773
     * Add user to the storage container
-
 
774
     *
-
 
775
     * @access public
-
 
776
     * @param  string Username
-
 
777
     * @param  string Password
-
 
778
     * @param  mixed  Additional parameters
-
 
779
     * @return mixed  True on success, PEAR error object on error
-
 
780
     *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
-
 
781
     */
-
 
782
    function addUser($username, $password, $additional = '')
-
 
783
    {
-
 
784
        return $this->storage->addUser($username, $password, $additional);
-
 
785
    }
-
 
786
 
-
 
787
    // }}}
-
 
788
    // {{{ removeUser()
-
 
789
 
-
 
790
    /**
-
 
791
     * Remove user from the storage container
-
 
792
     *
-
 
793
     * @access public
-
 
794
     * @param  string Username
-
 
795
     * @return mixed  True on success, PEAR error object on error
-
 
796
     *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
-
 
797
     */
-
 
798
    function removeUser($username)
-
 
799
    {
-
 
800
        return $this->storage->removeUser($username);
-
 
801
    }
-
 
802
 
-
 
803
    // }}}
-
 
804
    // {{{ _importGlobalVariable()
-
 
805
 
-
 
806
    /**
-
 
807
     * Import variables from special namespaces.
-
 
808
     *
-
 
809
     * @access private
-
 
810
     * @param string Type of variable (server, session, post)
-
 
811
     * @return array
-
 
812
     */
-
 
813
    function &_importGlobalVariable($variable)
-
 
814
    {
-
 
815
        $var = null;
-
 
816
 
-
 
817
        switch (strtolower($variable)) {
-
 
818
 
-
 
819
            case 'server' :
-
 
820
                if (isset($_SERVER)) {
-
 
821
                    $var = &$_SERVER;
-
 
822
                } else {
-
 
823
                    $var = &$GLOBALS['HTTP_SERVER_VARS'];
-
 
824
                }
-
 
825
                break;
-
 
826
 
-
 
827
            case 'session' :
-
 
828
                if (isset($_SESSION)) {
-
 
829
                    $var = &$_SESSION;
-
 
830
                } else {
-
 
831
                    $var = &$GLOBALS['HTTP_SESSION_VARS'];
-
 
832
                }
-
 
833
                break;
-
 
834
 
-
 
835
            case 'post' :
-
 
836
                if (isset($_POST)) {
-
 
837
                    $var = &$_POST;
-
 
838
                } else {
-
 
839
                    $var = &$GLOBALS['HTTP_POST_VARS'];
-
 
840
                }
-
 
841
                break;
-
 
842
 
-
 
843
            case 'cookie' :
-
 
844
                if (isset($_COOKIE)) {
-
 
845
                    $var = &$_COOKIE;
-
 
846
                } else {
-
 
847
                    $var = &$GLOBALS['HTTP_COOKIE_VARS'];
-
 
848
                }
-
 
849
                break;
-
 
850
 
-
 
851
            case 'get' :
-
 
852
                if (isset($_GET)) {
-
 
853
                    $var = &$_GET;
-
 
854
                } else {
-
 
855
                    $var = &$GLOBALS['HTTP_GET_VARS'];
-
 
856
                }
-
 
857
                break;
-
 
858
 
-
 
859
            default:
-
 
860
                break;
-
 
861
 
-
 
862
        }
-
 
863
 
-
 
864
        return $var;
-
 
865
    }
-
 
866
 
-
 
867
    // }}}
-
 
868
}
-
 
869
?>
-
 
870
1
<?php
-
 
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
-
 
3
 
-
 
4
/**
-
 
5
 * The main include file for Auth package
-
 
6
 *
-
 
7
 * PHP versions 4 and 5
-
 
8
 *
-
 
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:
-
 
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
-
 
13
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
14
 *
-
 
15
 * @category   Authentication
-
 
16
 * @package    Auth
-
 
17
 * @author     Martin Jansen <mj@php.net>
-
 
18
 * @author     Adam Ashley <aashley@php.net>
-
 
19
 * @copyright  2001-2006 The PHP Group
-
 
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
-
 
21
 * @version    CVS: $Id: Auth.php,v 1.2 2006-12-14 15:04:29 jp_milcent Exp $
-
 
22
 * @link       http://pear.php.net/package/Auth
-
 
23
 */
-
 
24
 
-
 
25
/**
-
 
26
 * Returned if session exceeds idle time
-
 
27
 */
-
 
28
define('AUTH_IDLED',                    -1);
-
 
29
/**
-
 
30
 * Returned if session has expired
-
 
31
 */
-
 
32
define('AUTH_EXPIRED',                  -2);
-
 
33
/** 
-
 
34
 * Returned if container is unable to authenticate user/password pair
-
 
35
 */
-
 
36
define('AUTH_WRONG_LOGIN',              -3);
-
 
37
/**
-
 
38
 * Returned if a container method is not supported.
-
 
39
 */
-
 
40
define('AUTH_METHOD_NOT_SUPPORTED',     -4);
-
 
41
/**
-
 
42
 * Returned if new Advanced security system detects a breach
-
 
43
 */
-
 
44
define('AUTH_SECURITY_BREACH',          -5);
-
 
45
/**
-
 
46
 * Returned if checkAuthCallback says session should not continue.
-
 
47
 */
-
 
48
define('AUTH_CALLBACK_ABORT',           -6);
-
 
49
 
-
 
50
/**
-
 
51
 * PEAR::Auth
-
 
52
 *
-
 
53
 * The PEAR::Auth class provides methods for creating an
-
 
54
 * authentication system using PHP.
-
 
55
 *
-
 
56
 * @category   Authentication
-
 
57
 * @package    Auth
-
 
58
 * @author     Martin Jansen <mj@php.net>
-
 
59
 * @author     Adam Ashley <aashley@php.net>
-
 
60
 * @copyright  2001-2006 The PHP Group
-
 
61
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
-
 
62
 * @version    Release: 1.4.3  File: $Revision: 1.2 $
-
 
63
 * @link       http://pear.php.net/package/Auth
-
 
64
 */
-
 
65
class Auth {
-
 
66
 
-
 
67
    // {{{ properties
-
 
68
 
-
 
69
    /**
-
 
70
     * Auth lifetime in seconds
-
 
71
     *
-
 
72
     * If this variable is set to 0, auth never expires
-
 
73
     *
-
 
74
     * @var  integer
-
 
75
     * @see  setExpire(), checkAuth()
-
 
76
     */
-
 
77
    var $expire = 0;
-
 
78
 
-
 
79
    /**
-
 
80
     * Has the auth session expired?
-
 
81
     *
-
 
82
     * @var   bool
-
 
83
     * @see   checkAuth()
-
 
84
     */
-
 
85
    var $expired = false;
-
 
86
 
-
 
87
    /**
-
 
88
     * Maximum idletime in seconds
-
 
89
     *
-
 
90
     * The difference to $expire is, that the idletime gets
-
 
91
     * refreshed each time checkAuth() is called. If this
-
 
92
     * variable is set to 0, idletime is never checked.
-
 
93
     *
-
 
94
     * @var integer
-
 
95
     * @see setIdle(), checkAuth()
-
 
96
     */
-
 
97
    var $idle = 0;
-
 
98
 
-
 
99
    /**
-
 
100
     * Is the maximum idletime over?
-
 
101
     *
-
 
102
     * @var boolean
-
 
103
     * @see checkAuth()
-
 
104
     */
-
 
105
    var $idled = false;
-
 
106
 
-
 
107
    /**
-
 
108
     * Storage object
-
 
109
     *
-
 
110
     * @var object
-
 
111
     * @see Auth(), validateLogin()
-
 
112
     */
-
 
113
    var $storage = '';
-
 
114
 
-
 
115
    /**
-
 
116
     * User-defined function that creates the login screen
-
 
117
     *
-
 
118
     * @var string
-
 
119
     */
-
 
120
    var $loginFunction = '';
-
 
121
 
-
 
122
    /**
-
 
123
     * Should the login form be displayed
-
 
124
     *
-
 
125
     * @var   bool
-
 
126
     * @see   setShowlogin()
-
 
127
     */
-
 
128
    var $showLogin = true;
-
 
129
    
-
 
130
    /**
-
 
131
      * Is Login Allowed from this page
-
 
132
      *
-
 
133
      * @var  bool
-
 
134
      * @see setAllowLogin
-
 
135
      */
-
 
136
    var $allowLogin = true;
-
 
137
 
-
 
138
    /**
-
 
139
     * Current authentication status
-
 
140
     *
-
 
141
     * @var string
-
 
142
     */
-
 
143
    var $status = '';
-
 
144
 
-
 
145
    /**
-
 
146
     * Username
-
 
147
     *
-
 
148
     * @var string
-
 
149
     */
-
 
150
    var $username = '';
-
 
151
 
-
 
152
    /**
-
 
153
     * Password
-
 
154
     *
-
 
155
     * @var string
-
 
156
     */
-
 
157
    var $password = '';
-
 
158
 
-
 
159
    /**
-
 
160
     * checkAuth callback function name
-
 
161
     *
-
 
162
     * @var string
-
 
163
     * @see setCheckAuthCallback()
-
 
164
     */
-
 
165
    var $checkAuthCallback = '';
-
 
166
 
-
 
167
    /**
-
 
168
     * Login callback function name
-
 
169
     *
-
 
170
     * @var string
-
 
171
     * @see setLoginCallback()
-
 
172
     */
-
 
173
    var $loginCallback = '';
-
 
174
 
-
 
175
    /**
-
 
176
     * Failed Login callback function name
-
 
177
     *
-
 
178
     * @var string
-
 
179
     * @see setFailedLoginCallback()
-
 
180
     */
-
 
181
    var $loginFailedCallback = '';
-
 
182
 
-
 
183
    /**
-
 
184
     * Logout callback function name
-
 
185
     *
-
 
186
     * @var string
-
 
187
     * @see setLogoutCallback()
-
 
188
     */
-
 
189
    var $logoutCallback = '';
-
 
190
 
-
 
191
    /**
-
 
192
     * Auth session-array name
-
 
193
     *
-
 
194
     * @var string
-
 
195
     */
-
 
196
    var $_sessionName = '_authsession';
-
 
197
 
-
 
198
    /**
-
 
199
     * Package Version
-
 
200
     *
-
 
201
     * @var string
-
 
202
     */
-
 
203
    var $version = "@version@";
-
 
204
 
-
 
205
    /**
-
 
206
     * Flag to use advanced security
-
 
207
     * When set extra checks will be made to see if the 
-
 
208
     * user's IP or useragent have changed across requests. 
-
 
209
     * Turned off by default to preserve BC.
-
 
210
     *
-
 
211
     * @var boolean
-
 
212
     */     
-
 
213
    var $advancedsecurity = false;
-
 
214
 
-
 
215
    /**
-
 
216
     * Username key in POST array
-
 
217
     *
-
 
218
     * @var string
-
 
219
     */
-
 
220
    var $_postUsername = 'username';
-
 
221
 
-
 
222
    /**
-
 
223
     * Password key in POST array
-
 
224
     *
-
 
225
     * @var string
-
 
226
     */
-
 
227
    var $_postPassword = 'password';
-
 
228
 
-
 
229
    /**
-
 
230
     * Holds a reference to the session auth variable
-
 
231
     * @var array
-
 
232
     */
-
 
233
    var $session;
-
 
234
 
-
 
235
    /**
-
 
236
     * Holds a reference to the global server variable
-
 
237
     * @var array
-
 
238
     */
-
 
239
    var $server;
-
 
240
 
-
 
241
    /**
-
 
242
     * Holds a reference to the global post variable
-
 
243
     * @var array
-
 
244
     */
-
 
245
    var $post;
-
 
246
 
-
 
247
    /**
-
 
248
     * Holds a reference to the global cookie variable
-
 
249
     * @var array
-
 
250
     */
-
 
251
    var $cookie;
-
 
252
 
-
 
253
    /**
-
 
254
     * A hash to hold various superglobals as reference
-
 
255
     * @var array
-
 
256
     */
-
 
257
    var $authdata;
-
 
258
    
-
 
259
    /**
-
 
260
      * How many times has checkAuth been called
-
 
261
      * var int
-
 
262
      */
-
 
263
    var $authChecks = 0;
-
 
264
 
-
 
265
    // }}}
-
 
266
    // {{{ Auth() [constructor]
-
 
267
 
-
 
268
    /**
-
 
269
     * Constructor
-
 
270
     *
-
 
271
     * Set up the storage driver.
-
 
272
     *
-
 
273
     * @param string    Type of the storage driver
-
 
274
     * @param mixed     Additional options for the storage driver
-
 
275
     *                  (example: if you are using DB as the storage
-
 
276
     *                   driver, you have to pass the dsn string here)
-
 
277
     *
-
 
278
     * @param string    Name of the function that creates the login form
-
 
279
     * @param boolean   Should the login form be displayed if neccessary?
-
 
280
     * @return void
-
 
281
     */
-
 
282
    function Auth($storageDriver, $options = '', $loginFunction = '', $showLogin = true)
-
 
283
    {
-
 
284
        $this->applyAuthOptions($options);
-
 
285
 
-
 
286
        // Start the session suppress error if already started
-
 
287
        if(!session_id()){
-
 
288
            @session_start();
-
 
289
            if(!session_id()) {
-
 
290
                // Throw error
-
 
291
                include_once 'PEAR.php';
-
 
292
                PEAR::throwError('Session could not be started by Auth, '
-
 
293
                        .'possibly headers are already sent, try putting '
-
 
294
                        .'ob_start in the beginning of your script');
-
 
295
            }
-
 
296
        }
-
 
297
 
-
 
298
        // Make Sure Auth session variable is there
-
 
299
        if(!isset($_SESSION[$this->_sessionName])) {
-
 
300
            $_SESSION[$this->_sessionName] = array();
-
 
301
        }
-
 
302
 
-
 
303
        // Assign Some globals to internal references, this will replace _importGlobalVariable
-
 
304
        $this->session =& $_SESSION[$this->_sessionName];
-
 
305
        $this->server =& $_SERVER;
-
 
306
        $this->post =& $_POST;
-
 
307
        $this->cookie =& $_COOKIE;
-
 
308
 
-
 
309
        if ($loginFunction != '' && is_callable($loginFunction)) {
-
 
310
            $this->loginFunction = $loginFunction;
-
 
311
        }
-
 
312
 
-
 
313
        if (is_bool($showLogin)) {
-
 
314
            $this->showLogin = $showLogin;
-
 
315
        }
-
 
316
 
-
 
317
        if (is_object($storageDriver)) {
-
 
318
            $this->storage =& $storageDriver;
-
 
319
            // Pass a reference to auth to the container, ugly but works
-
 
320
            // this is used by the DB container to use method setAuthData not staticaly.
-
 
321
            $this->storage->_auth_obj =& $this;
-
 
322
        } else {
-
 
323
            // $this->storage = $this->_factory($storageDriver, $options);
-
 
324
            // 
-
 
325
            $this->storage_driver = $storageDriver;
-
 
326
            $this->storage_options =& $options;
-
 
327
        }
-
 
328
    }
-
 
329
 
-
 
330
    // }}}
-
 
331
    // {{{ applyAuthOptions()
-
 
332
 
-
 
333
    /**
-
 
334
      * Set the Auth options 
-
 
335
      *
-
 
336
      * Some options which are Auth specific will be applied
-
 
337
      * the rest will be left for usage by the container
-
 
338
      * 
-
 
339
      * @param array    An array of Auth options
-
 
340
      * @return array   The options which were not applied
-
 
341
      * @access private
-
 
342
      */
-
 
343
    function &applyAuthOptions(&$options)
-
 
344
    {
-
 
345
        if(is_array($options)){
-
 
346
            if (!empty($options['sessionName'])) {
-
 
347
                $this->_sessionName = $options['sessionName'];
-
 
348
                unset($options['sessionName']);
-
 
349
            }
-
 
350
            if (isset($options['allowLogin'])) {
-
 
351
                $this->allowLogin = $options['allowLogin'];
-
 
352
                unset($options['allowLogin']);
-
 
353
            }
-
 
354
            if (!empty($options['postUsername'])) {
-
 
355
                $this->_postUsername = $options['postUsername'];
-
 
356
                unset($options['postUsername']);
-
 
357
            }
-
 
358
            if (!empty($options['postPassword'])) {
-
 
359
                $this->_postPassword = $options['postPassword'];
-
 
360
                unset($options['postPassword']);
-
 
361
            }
-
 
362
            if (isset($options['advancedsecurity'])) {
-
 
363
                $this->advancedsecurity = $options['advancedsecurity'];
-
 
364
                unset($options['advancedsecurity']);
-
 
365
            }
-
 
366
        }
-
 
367
        return($options);
-
 
368
    }
-
 
369
 
-
 
370
    // }}}
-
 
371
    // {{{ _loadStorage()
-
 
372
    
-
 
373
    /**
-
 
374
      * Load Storage Driver if not already loaded
-
 
375
      *
-
 
376
      * Suspend storage instantiation to make Auth lighter to use 
-
 
377
      * for calls which do not require login
-
 
378
      *
-
 
379
      * @return bool    True if the conainer is loaded, false if the container
-
 
380
      *                 is already loaded
-
 
381
      * @access private
-
 
382
      */
-
 
383
    function _loadStorage()
-
 
384
    {
-
 
385
        if(!is_object($this->storage)) {
-
 
386
            $this->storage =& $this->_factory($this->storage_driver, 
-
 
387
                    $this->storage_options);
-
 
388
            $this->storage->_auth_obj =& $this;
-
 
389
            return(true);
-
 
390
        }
-
 
391
        return(false);
-
 
392
    }
-
 
393
 
-
 
394
    // }}}
-
 
395
    // {{{ _factory()
-
 
396
 
-
 
397
    /**
-
 
398
     * Return a storage driver based on $driver and $options
-
 
399
     *
-
 
400
     * @static
-
 
401
     * @param  string $driver  Type of storage class to return
-
 
402
     * @param  string $options Optional parameters for the storage class
-
 
403
     * @return object Object   Storage object
-
 
404
     * @access private
-
 
405
     */
-
 
406
    function &_factory($driver, $options = '')
-
 
407
    {
-
 
408
        $storage_class = 'Auth_Container_' . $driver;
-
 
409
        include_once 'Auth/Container/' . $driver . '.php';
-
 
410
        $obj =& new $storage_class($options);
-
 
411
        return $obj;
-
 
412
    }
-
 
413
 
-
 
414
    // }}}
-
 
415
    // {{{ assignData()
-
 
416
 
-
 
417
    /**
-
 
418
     * Assign data from login form to internal values
-
 
419
     *
-
 
420
     * This function takes the values for username and password
-
 
421
     * from $HTTP_POST_VARS/$_POST and assigns them to internal variables.
-
 
422
     * If you wish to use another source apart from $HTTP_POST_VARS/$_POST,
-
 
423
     * you have to derive this function.
-
 
424
     *
-
 
425
     * @global $HTTP_POST_VARS, $_POST
-
 
426
     * @see    Auth
-
 
427
     * @return void
-
 
428
     * @access private
-
 
429
     */
-
 
430
    function assignData()
-
 
431
    {
-
 
432
        if (   isset($this->post[$this->_postUsername]) 
-
 
433
            && $this->post[$this->_postUsername] != '') {
-
 
434
            $this->username = (get_magic_quotes_gpc() == 1 
-
 
435
                    ? stripslashes($this->post[$this->_postUsername]) 
-
 
436
                    : $this->post[$this->_postUsername]);
-
 
437
        }
-
 
438
        if (   isset($this->post[$this->_postPassword]) 
-
 
439
            && $this->post[$this->_postPassword] != '') {
-
 
440
            $this->password = (get_magic_quotes_gpc() == 1 
-
 
441
                    ? stripslashes($this->post[$this->_postPassword]) 
-
 
442
                    : $this->post[$this->_postPassword] );
-
 
443
        }
-
 
444
    }
-
 
445
 
-
 
446
    // }}}
-
 
447
    // {{{ start()
-
 
448
 
-
 
449
    /**
-
 
450
     * Start new auth session
-
 
451
     *
-
 
452
     * @return void
-
 
453
     * @access public
-
 
454
     */
-
 
455
    function start()
-
 
456
    {
-
 
457
        $this->assignData();
-
 
458
        if (!$this->checkAuth() && $this->allowLogin) {
-
 
459
            $this->login();
-
 
460
        }
-
 
461
    }
-
 
462
 
-
 
463
    // }}}
-
 
464
    // {{{ login()
-
 
465
 
-
 
466
    /**
-
 
467
     * Login function
-
 
468
     *
-
 
469
     * @return void
-
 
470
     * @access private
-
 
471
     */
-
 
472
    function login()
-
 
473
    {
-
 
474
        $login_ok = false;
-
 
475
        $this->_loadStorage();
-
 
476
        
-
 
477
        // Check if using challenge response
-
 
478
        (isset($this->post['authsecret']) && $this->post['authsecret'] == 1) 
-
 
479
            ? $usingChap = true 
-
 
480
            : $usingChap = false;
-
 
481
 
-
 
482
        
-
 
483
        // When the user has already entered a username, we have to validate it.
-
 
484
        if (!empty($this->username)) {
-
 
485
            if (true === $this->storage->fetchData($this->username, $this->password, $usingChap)) {
-
 
486
                $this->session['challengekey'] = md5($this->username.$this->password);
-
 
487
                $login_ok = true;
-
 
488
            }
-
 
489
        }
-
 
490
 
-
 
491
        if (!empty($this->username) && $login_ok) {
-
 
492
            $this->setAuth($this->username);
-
 
493
            if (is_callable($this->loginCallback)) {
-
 
494
                call_user_func_array($this->loginCallback, array($this->username, &$this));
-
 
495
            }
-
 
496
        }
-
 
497
 
-
 
498
        // If the login failed or the user entered no username, 
-
 
499
        // output the login screen again.
-
 
500
        if (!empty($this->username) && !$login_ok) {
-
 
501
            $this->status = AUTH_WRONG_LOGIN;
-
 
502
            if (is_callable($this->loginFailedCallback)) {
-
 
503
                call_user_func_array($this->loginFailedCallback, array($this->username, &$this));
-
 
504
            }
-
 
505
        }
-
 
506
 
-
 
507
        if ((empty($this->username) || !$login_ok) && $this->showLogin) {
-
 
508
            if (is_callable($this->loginFunction)) {
-
 
509
                call_user_func_array($this->loginFunction, array($this->username, $this->status, &$this));
-
 
510
            } else {
-
 
511
                // BC fix Auth used to use drawLogin for this
-
 
512
                // call is sub classes implement this
-
 
513
                if (is_callable(array($this, 'drawLogin'))) {
-
 
514
                    return $this->drawLogin($this->username, $this);
-
 
515
                }
-
 
516
 
-
 
517
                // New Login form
-
 
518
                include_once 'Auth/Frontend/Html.php';
-
 
519
                return Auth_Frontend_Html::render($this, $this->username);
-
 
520
            }
-
 
521
        } else {
-
 
522
            return;
-
 
523
        }
-
 
524
    }
-
 
525
 
-
 
526
    // }}}
-
 
527
    // {{{ setExpire()
-
 
528
 
-
 
529
    /**
-
 
530
     * Set the maximum expire time
-
 
531
     *
-
 
532
     * @param  integer time in seconds
-
 
533
     * @param  bool    add time to current expire time or not
-
 
534
     * @return void
-
 
535
     * @access public
-
 
536
     */
-
 
537
    function setExpire($time, $add = false)
-
 
538
    {
-
 
539
        $add ? $this->expire += $time : $this->expire = $time;
-
 
540
    }
-
 
541
 
-
 
542
    // }}}
-
 
543
    // {{{ setIdle()
-
 
544
 
-
 
545
    /**
-
 
546
     * Set the maximum idle time
-
 
547
     *
-
 
548
     * @param  integer time in seconds
-
 
549
     * @param  bool    add time to current maximum idle time or not
-
 
550
     * @return void
-
 
551
     * @access public
-
 
552
     */
-
 
553
    function setIdle($time, $add = false)
-
 
554
    {
-
 
555
        $add ? $this->idle += $time : $this->idle = $time;
-
 
556
    }
-
 
557
 
-
 
558
    // }}}
-
 
559
    // {{{ setSessionName()
-
 
560
 
-
 
561
    /**
-
 
562
     * Set name of the session to a customized value.
-
 
563
     *
-
 
564
     * If you are using multiple instances of PEAR::Auth
-
 
565
     * on the same domain, you can change the name of
-
 
566
     * session per application via this function.
-
 
567
     * This will chnage the name of the session variable 
-
 
568
     * auth uses to store it's data in the session
-
 
569
     *
-
 
570
     * @param  string New name for the session
-
 
571
     * @return void
-
 
572
     * @access public
-
 
573
     */
-
 
574
    function setSessionName($name = 'session')
-
 
575
    {
-
 
576
        $this->_sessionName = '_auth_'.$name;
-
 
577
        $this->session =& $_SESSION[$this->_sessionName];
-
 
578
    }
-
 
579
 
-
 
580
    // }}}
-
 
581
    // {{{ setShowLogin()
-
 
582
 
-
 
583
    /**
-
 
584
     * Should the login form be displayed if neccessary?
-
 
585
     *
-
 
586
     * @param  bool    show login form or not
-
 
587
     * @return void
-
 
588
     * @access public
-
 
589
     */
-
 
590
    function setShowLogin($showLogin = true)
-
 
591
    {
-
 
592
        $this->showLogin = $showLogin;
-
 
593
    }
-
 
594
 
-
 
595
    // }}}
-
 
596
    // {{{ setAllowLogin()
-
 
597
 
-
 
598
    /**
-
 
599
     * Should the login form be displayed if neccessary?
-
 
600
     *
-
 
601
     * @param  bool    show login form or not
-
 
602
     * @return void
-
 
603
     * @access public
-
 
604
     */
-
 
605
    function setAllowLogin($allowLogin = true)
-
 
606
    {
-
 
607
        $this->allowLogin = $allowLogin;
-
 
608
    }
-
 
609
 
-
 
610
    // }}}
-
 
611
    // {{{ setCheckAuthCallback()
-
 
612
 
-
 
613
    /**
-
 
614
     * Register a callback function to be called whenever the validity of the login is checked
-
 
615
     * The function will receive two parameters, the username and a reference to the auth object.
-
 
616
     *
-
 
617
     * @param  string  callback function name
-
 
618
     * @return void
-
 
619
     * @access public
-
 
620
     * @since Method available since Release 1.4.3
-
 
621
     */
-
 
622
    function setCheckAuthCallback($checkAuthCallback)
-
 
623
    {
-
 
624
        $this->checkAuthCallback = $checkAuthCallback;
-
 
625
    }
-
 
626
 
-
 
627
    // }}}
-
 
628
    // {{{ setLoginCallback()
-
 
629
    
-
 
630
    /**
-
 
631
     * Register a callback function to be called on user login.
-
 
632
     * The function will receive two parameters, the username and a reference to the auth object.
-
 
633
     *
-
 
634
     * @param  string  callback function name
-
 
635
     * @return void
-
 
636
     * @see    setLogoutCallback()
-
 
637
     * @access public
-
 
638
     */
-
 
639
    function setLoginCallback($loginCallback)
-
 
640
    {
-
 
641
        $this->loginCallback = $loginCallback;
-
 
642
    }
-
 
643
 
-
 
644
    // }}}
-
 
645
    // {{{ setFailedLoginCallback()
-
 
646
 
-
 
647
    /**
-
 
648
     * Register a callback function to be called on failed user login.
-
 
649
     * The function will receive two parameters, the username and a reference to the auth object.
-
 
650
     *
-
 
651
     * @param  string  callback function name
-
 
652
     * @return void
-
 
653
     * @access public
-
 
654
     */
-
 
655
    function setFailedLoginCallback($loginFailedCallback)
-
 
656
    {
-
 
657
        $this->loginFailedCallback = $loginFailedCallback;
-
 
658
    }
-
 
659
 
-
 
660
    // }}}
-
 
661
    // {{{ setLogoutCallback()
-
 
662
 
-
 
663
    /**
-
 
664
     * Register a callback function to be called on user logout.
-
 
665
     * The function will receive three parameters, the username and a reference to the auth object.
-
 
666
     *
-
 
667
     * @param  string  callback function name
-
 
668
     * @return void
-
 
669
     * @see    setLoginCallback()
-
 
670
     * @access public
-
 
671
     */
-
 
672
    function setLogoutCallback($logoutCallback)
-
 
673
    {
-
 
674
        $this->logoutCallback = $logoutCallback;
-
 
675
    }
-
 
676
 
-
 
677
    // }}}
-
 
678
    // {{{ setAuthData()
-
 
679
 
-
 
680
    /**
-
 
681
     * Register additional information that is to be stored
-
 
682
     * in the session.
-
 
683
     *
-
 
684
     * @param  string  Name of the data field
-
 
685
     * @param  mixed   Value of the data field
-
 
686
     * @param  boolean Should existing data be overwritten? (default
-
 
687
     *                 is true)
-
 
688
     * @return void
-
 
689
     * @access public
-
 
690
     */
-
 
691
    function setAuthData($name, $value, $overwrite = true)
-
 
692
    {
-
 
693
        if (!empty($this->session['data'][$name]) && $overwrite == false) {
-
 
694
            return;
-
 
695
        }
-
 
696
        $this->session['data'][$name] = $value;
-
 
697
    }
-
 
698
 
-
 
699
    // }}}
-
 
700
    // {{{ getAuthData()
-
 
701
 
-
 
702
    /**
-
 
703
     * Get additional information that is stored in the session.
-
 
704
     *
-
 
705
     * If no value for the first parameter is passed, the method will
-
 
706
     * return all data that is currently stored.
-
 
707
     *
-
 
708
     * @param  string Name of the data field
-
 
709
     * @return mixed  Value of the data field.
-
 
710
     * @access public
-
 
711
     */
-
 
712
    function getAuthData($name = null)
-
 
713
    {
-
 
714
        if (!isset($this->session['data'])) {
-
 
715
            return null;
-
 
716
        }    
-
 
717
        if(!isset($name)) {
-
 
718
            return $this->session['data'];
-
 
719
        }
-
 
720
        if (isset($name) && isset($this->session['data'][$name])) {
-
 
721
            return $this->session['data'][$name];
-
 
722
        }
-
 
723
        return null;        
-
 
724
    }
-
 
725
 
-
 
726
    // }}}
-
 
727
    // {{{ setAuth()
-
 
728
 
-
 
729
    /**
-
 
730
     * Register variable in a session telling that the user
-
 
731
     * has logged in successfully
-
 
732
     *
-
 
733
     * @param  string Username
-
 
734
     * @return void
-
 
735
     * @access public
-
 
736
     */
-
 
737
    function setAuth($username)
-
 
738
    {
-
 
739
    
-
 
740
        // #2021 - Change the session id to avoid session fixation attacks php 4.3.3 > 
-
 
741
        session_regenerate_id(true);
-
 
742
 
-
 
743
        if (!isset($this->session) || !is_array($this->session)) {
-
 
744
            $this->session = array();
-
 
745
        }
-
 
746
 
-
 
747
        if (!isset($this->session['data'])) {
-
 
748
            $this->session['data'] = array();
-
 
749
        }
-
 
750
 
-
 
751
        $this->session['sessionip'] = isset($this->server['REMOTE_ADDR']) 
-
 
752
            ? $this->server['REMOTE_ADDR'] 
-
 
753
            : '';
-
 
754
        $this->session['sessionuseragent'] = isset($this->server['HTTP_USER_AGENT']) 
-
 
755
            ? $this->server['HTTP_USER_AGENT'] 
-
 
756
            : '';
-
 
757
 
-
 
758
        // This should be set by the container to something more safe
-
 
759
        // Like md5(passwd.microtime)
-
 
760
        if(empty($this->session['challengekey'])) {
-
 
761
            $this->session['challengekey'] = md5($username.microtime());
-
 
762
        }
-
 
763
 
-
 
764
        $this->session['challengecookie'] = md5($this->session['challengekey'].microtime());
-
 
765
        setcookie('authchallenge', $this->session['challengecookie']);
-
 
766
 
-
 
767
        $this->session['registered'] = true;
-
 
768
        $this->session['username']   = $username;
-
 
769
        $this->session['timestamp']  = time();
-
 
770
        $this->session['idle']       = time();
-
 
771
    }
-
 
772
 
-
 
773
    // }}}
-
 
774
    // {{{ setAdvancedSecurity()
-
 
775
    
-
 
776
    /**
-
 
777
      * Enables advanced security checks
-
 
778
      *
-
 
779
      * Currently only ip change and useragent change 
-
 
780
      * are detected
-
 
781
      * @todo Add challenge cookies - Create a cookie which changes every time 
-
 
782
      *       and contains some challenge key which the server can verify with
-
 
783
      *       a session var cookie might need to be crypted (user pass)
-
 
784
      * @param bool Enable or disable
-
 
785
      * @return void
-
 
786
      * @access public
-
 
787
      */
-
 
788
    function setAdvancedSecurity($flag=true)
-
 
789
    {
-
 
790
        $this->advancedsecurity = $flag;
-
 
791
    }
-
 
792
 
-
 
793
    // }}}
-
 
794
    // {{{ checkAuth()
-
 
795
 
-
 
796
    /**
-
 
797
     * Checks if there is a session with valid auth information.
-
 
798
     *
-
 
799
     * @access public
-
 
800
     * @return boolean  Whether or not the user is authenticated.
-
 
801
     */
-
 
802
    function checkAuth()
-
 
803
    {
-
 
804
        $this->authChecks++;
-
 
805
        if (isset($this->session)) {
-
 
806
            // Check if authentication session is expired
-
 
807
            if (   $this->expire > 0
-
 
808
                && isset($this->session['timestamp'])
-
 
809
                && ($this->session['timestamp'] + $this->expire) < time()) {
-
 
810
                $this->expired = true;
-
 
811
                $this->status = AUTH_EXPIRED;
-
 
812
                $this->logout();
-
 
813
                return false;
-
 
814
            }
-
 
815
 
-
 
816
            // Check if maximum idle time is reached
-
 
817
            if (   $this->idle > 0
-
 
818
                && isset($this->session['idle']) 
-
 
819
                && ($this->session['idle'] + $this->idle) < time()) {
-
 
820
                $this->idled = true;
-
 
821
                $this->status = AUTH_IDLED;
-
 
822
                $this->logout();
-
 
823
                return false;
-
 
824
            }
-
 
825
 
-
 
826
            if (   isset($this->session['registered']) 
-
 
827
                && isset($this->session['username']) 
-
 
828
                && $this->session['registered'] == true 
-
 
829
                && $this->session['username'] != '') {
-
 
830
                Auth::updateIdle();
-
 
831
 
-
 
832
                if ($this->advancedsecurity) {
-
 
833
                    
-
 
834
                    // Only Generate the challenge once
-
 
835
                    if($this->authChecks == 1) {
-
 
836
                        $this->session['challengecookieold'] = $this->session['challengecookie'];
-
 
837
                        $this->session['challengecookie'] = md5($this->session['challengekey'].microtime());
-
 
838
                        setcookie('authchallenge', $this->session['challengecookie']);
-
 
839
                    }
-
 
840
                    
-
 
841
                    // Check for ip change
-
 
842
                    if (   isset($this->server['REMOTE_ADDR']) 
-
 
843
                        && $this->session['sessionip'] != $this->server['REMOTE_ADDR']) {
-
 
844
                        // Check if the IP of the user has changed, if so we 
-
 
845
                        // assume a man in the middle attack and log him out
-
 
846
                        $this->expired = true;
-
 
847
                        $this->status = AUTH_SECURITY_BREACH;
-
 
848
                        $this->logout();
-
 
849
                        return false;
-
 
850
                    }
-
 
851
                    
-
 
852
                    // Check for useragent change
-
 
853
                    if (   isset($this->server['HTTP_USER_AGENT']) 
-
 
854
                        && $this->session['sessionuseragent'] != $this->server['HTTP_USER_AGENT']) {
-
 
855
                        // Check if the User-Agent of the user has changed, if 
-
 
856
                        // so we assume a man in the middle attack and log him out
-
 
857
                        $this->expired = true;
-
 
858
                        $this->status = AUTH_SECURITY_BREACH;
-
 
859
                        $this->logout();
-
 
860
                        return false;
-
 
861
                    }
-
 
862
    
-
 
863
                    // Check challenge cookie here, if challengecookieold is not set 
-
 
864
                    // this is the first time and check is skipped
-
 
865
                    // TODO when user open two pages similtaneuly (open in new window,open 
-
 
866
                    // in tab) auth breach is caused find out a way around that if possible
-
 
867
                    if (   isset($this->session['challengecookieold']) 
-
 
868
                        && $this->session['challengecookieold'] != $this->cookie['authchallenge']) {
-
 
869
                        $this->expired = true;
-
 
870
                        $this->status = AUTH_SECURITY_BREACH;
-
 
871
                        $this->logout();
-
 
872
                        $this->login();
-
 
873
                        return false;
-
 
874
                    }
-
 
875
                }
-
 
876
 
-
 
877
                if (is_callable($this->checkAuthCallback)) {
-
 
878
                    $checkCallback = call_user_func_array($this->checkAuthCallback, array($this->username, &$this));
-
 
879
                    if ($checkCallback == false) {
-
 
880
                        $this->expired = true;
-
 
881
                        $this->status = AUTH_CALLBACK_ABORT;
-
 
882
                        $this->logout();
-
 
883
                        return false;
-
 
884
                    }
-
 
885
                }
-
 
886
 
-
 
887
                return true;
-
 
888
            }
-
 
889
        }
-
 
890
        return false;
-
 
891
    }
-
 
892
 
-
 
893
    // }}}
-
 
894
    // {{{ staticCheckAuth() [static]
-
 
895
 
-
 
896
    /**
-
 
897
     * Statically checks if there is a session with valid auth information.
-
 
898
     *
-
 
899
     * @access public
-
 
900
     * @see checkAuth
-
 
901
     * @return boolean  Whether or not the user is authenticated.
-
 
902
     * @static
-
 
903
     */
-
 
904
    function staticCheckAuth($options = null)
-
 
905
    {
-
 
906
        static $staticAuth;
-
 
907
        if(!isset($staticAuth)) {
-
 
908
            $staticAuth = new Auth('null', $options);
-
 
909
        }
-
 
910
        return $staticAuth->checkAuth();
-
 
911
    }
-
 
912
 
-
 
913
    // }}}
-
 
914
    // {{{ getAuth()
-
 
915
 
-
 
916
    /**
-
 
917
     * Has the user been authenticated?
-
 
918
     *
-
 
919
     * @access public
-
 
920
     * @return bool  True if the user is logged in, otherwise false.
-
 
921
     */
-
 
922
    function getAuth()
-
 
923
    {
-
 
924
        return $this->checkAuth();
-
 
925
    }
-
 
926
 
-
 
927
    // }}}
-
 
928
    // {{{ logout()
-
 
929
 
-
 
930
    /**
-
 
931
     * Logout function
-
 
932
     *
-
 
933
     * This function clears any auth tokens in the currently
-
 
934
     * active session and executes the logout callback function,
-
 
935
     * if any
-
 
936
     *
-
 
937
     * @access public
-
 
938
     * @return void
-
 
939
     */
-
 
940
    function logout()
-
 
941
    {
-
 
942
        if (is_callable($this->logoutCallback)) {
-
 
943
            call_user_func_array($this->logoutCallback, array($this->session['username'], &$this));
-
 
944
        }
-
 
945
 
-
 
946
        $this->username = '';
-
 
947
        $this->password = '';
-
 
948
        
-
 
949
        $this->session = null;
-
 
950
    }
-
 
951
 
-
 
952
    // }}}
-
 
953
    // {{{ updateIdle()
-
 
954
 
-
 
955
    /**
-
 
956
     * Update the idletime
-
 
957
     *
-
 
958
     * @access private
-
 
959
     * @return void
-
 
960
     */
-
 
961
    function updateIdle()
-
 
962
    {
-
 
963
        $this->session['idle'] = time();
-
 
964
    }
-
 
965
 
-
 
966
    // }}}
-
 
967
    // {{{ getUsername()
-
 
968
 
-
 
969
    /**
-
 
970
     * Get the username
-
 
971
     *
-
 
972
     * @return string
-
 
973
     * @access public
-
 
974
     */
-
 
975
    function getUsername()
-
 
976
    {
-
 
977
        if (isset($this->session['username'])) {
-
 
978
            return($this->session['username']);
-
 
979
        }
-
 
980
        return('');
-
 
981
    }
-
 
982
 
-
 
983
    // }}}
-
 
984
    // {{{ getStatus()
-
 
985
 
-
 
986
    /**
-
 
987
     * Get the current status
-
 
988
     *
-
 
989
     * @return string
-
 
990
     * @access public
-
 
991
     */
-
 
992
    function getStatus()
-
 
993
    {
-
 
994
        return $this->status;
-
 
995
    }
-
 
996
 
-
 
997
    // }}}
-
 
998
    // {{{ getPostUsernameField()
-
 
999
    
-
 
1000
    /**
-
 
1001
     * Gets the post varible used for the username
-
 
1002
     * 
-
 
1003
     * @return string
-
 
1004
     * @access public
-
 
1005
     */
-
 
1006
    function getPostUsernameField()
-
 
1007
    {
-
 
1008
        return($this->_postUsername);
-
 
1009
    }
-
 
1010
 
-
 
1011
    // }}}
-
 
1012
    // {{{ getPostPasswordField()
-
 
1013
 
-
 
1014
    /**
-
 
1015
     * Gets the post varible used for the username
-
 
1016
     * 
-
 
1017
     * @return string
-
 
1018
     * @access public
-
 
1019
     */
-
 
1020
    function getPostPasswordField()
-
 
1021
    {
-
 
1022
        return($this->_postPassword);
-
 
1023
    }
-
 
1024
 
-
 
1025
    // }}}
-
 
1026
    // {{{ sessionValidThru()
-
 
1027
 
-
 
1028
    /**
-
 
1029
     * Returns the time up to the session is valid
-
 
1030
     *
-
 
1031
     * @access public
-
 
1032
     * @return integer
-
 
1033
     */
-
 
1034
    function sessionValidThru()
-
 
1035
    {
-
 
1036
        if (!isset($this->session['idle'])) {
-
 
1037
            return 0;
-
 
1038
        }
-
 
1039
        if ($this->idle == 0) {
-
 
1040
            return 0;
-
 
1041
        }
-
 
1042
        return ($this->session['idle'] + $this->idle);
-
 
1043
    }
-
 
1044
 
-
 
1045
    // }}}
-
 
1046
    // {{{ listUsers()
-
 
1047
 
-
 
1048
    /**
-
 
1049
     * List all users that are currently available in the storage
-
 
1050
     * container
-
 
1051
     *
-
 
1052
     * @access public
-
 
1053
     * @return array
-
 
1054
     */
-
 
1055
    function listUsers()
-
 
1056
    {
-
 
1057
        $this->_loadStorage();
-
 
1058
        return $this->storage->listUsers();
-
 
1059
    }
-
 
1060
 
-
 
1061
    // }}}
-
 
1062
    // {{{ addUser()
-
 
1063
 
-
 
1064
    /**
-
 
1065
     * Add user to the storage container
-
 
1066
     *
-
 
1067
     * @access public
-
 
1068
     * @param  string Username
-
 
1069
     * @param  string Password
-
 
1070
     * @param  mixed  Additional parameters
-
 
1071
     * @return mixed  True on success, PEAR error object on error
-
 
1072
     *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
-
 
1073
     */
-
 
1074
    function addUser($username, $password, $additional = '')
-
 
1075
    {
-
 
1076
        $this->_loadStorage();
-
 
1077
        return $this->storage->addUser($username, $password, $additional);
-
 
1078
    }
-
 
1079
 
-
 
1080
    // }}}
-
 
1081
    // {{{ removeUser()
-
 
1082
 
-
 
1083
    /**
-
 
1084
     * Remove user from the storage container
-
 
1085
     *
-
 
1086
     * @access public
-
 
1087
     * @param  string Username
-
 
1088
     * @return mixed  True on success, PEAR error object on error
-
 
1089
     *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
-
 
1090
     */
-
 
1091
    function removeUser($username)
-
 
1092
    {
-
 
1093
        $this->_loadStorage();
-
 
1094
        return $this->storage->removeUser($username);
-
 
1095
    }
-
 
1096
 
-
 
1097
    // }}}
-
 
1098
    // {{{ changePassword()
-
 
1099
 
-
 
1100
    /**
-
 
1101
     * Change password for user in the storage container
-
 
1102
     *
-
 
1103
     * @access public
-
 
1104
     * @param string Username
-
 
1105
     * @param string The new password 
-
 
1106
     * @return mixed True on success, PEAR error object on error
-
 
1107
     *               and AUTH_METHOD_NOT_SUPPORTED otherwise.
-
 
1108
     */
-
 
1109
    function changePassword($username, $password)
-
 
1110
    {
-
 
1111
        $this->_loadStorage();
-
 
1112
        return $this->storage->changePassword($username, $password);
-
 
1113
    }
-
 
1114
 
-
 
1115
    // }}}
-
 
1116
 
-
 
1117
}
-
 
1118
?>
-
 
1119