Subversion Repositories Applications.papyrus

Rev

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

Rev 320 Rev 1173
Line 1... Line 1...
1
<?php
1
<?php
2
//
-
 
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.               |
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
15
// +----------------------------------------------------------------------+
-
 
16
// | Authors: Martin Jansen <mj@php.net>                                  |
-
 
17
// +----------------------------------------------------------------------+
-
 
18
//
-
 
19
// $Id: Container.php,v 1.1 2005-03-30 08:50:33 jpm Exp $
-
 
20
//
-
 
Line -... Line 3...
-
 
3
 
-
 
4
/**
-
 
5
 * Auth_Container Base Class
-
 
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
21
 
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: Container.php,v 1.2 2006-12-14 15:04:28 jp_milcent Exp $
-
 
22
 * @link       http://pear.php.net/package/Auth
Line 22... Line 23...
22
define("AUTH_METHOD_NOT_SUPPORTED", -4);
23
 */
23
 
24
 
24
/**
25
/**
25
 * Storage class for fetching login data
26
 * Storage class for fetching login data
26
 *
27
 *
-
 
28
 * @category   Authentication
-
 
29
 * @package    Auth
-
 
30
 * @author     Martin Jansen <mj@php.net>
-
 
31
 * @author     Adam Ashley <aashley@php.net>
-
 
32
 * @copyright  2001-2006 The PHP Group
-
 
33
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
27
 * @author   Martin Jansen <mj@php.net>
34
 * @version    Release: 1.4.3  File: $Revision: 1.2 $
28
 * @package  Auth
35
 * @link       http://pear.php.net/package/Auth
29
 */
36
 */
Line -... Line 37...
-
 
37
class Auth_Container
-
 
38
{
30
class Auth_Container
39
 
31
{
40
    // {{{ properties
32
 
41
 
33
    /**
42
    /**
34
     * User that is currently selected from the storage container.
43
     * User that is currently selected from the storage container.
35
     *
44
     *
Line -... Line 45...
-
 
45
     * @access public
36
     * @access public
46
     */
Line 37... Line 47...
37
     */
47
    var $activeUser = "";
38
    var $activeUser = "";
48
 
39
 
49
    // }}}
40
    // {{{ Constructor
50
    // {{{ Auth_Container() [constructor]
Line 58... Line 68...
58
     *
68
     *
59
     * Has to be overwritten by each storage class
69
     * Has to be overwritten by each storage class
60
     *
70
     *
61
     * @access public
71
     * @access public
62
     */
72
     */
63
    function fetchData() 
73
    function fetchData($username, $password, $isChallengeResponse=false)
64
    {
74
    {
65
    }
75
    }
Line 66... Line 76...
66
 
76
 
67
    // }}}
77
    // }}}
Line 80... Line 90...
80
     */
90
     */
81
    function verifyPassword($password1, $password2, $cryptType = "md5")
91
    function verifyPassword($password1, $password2, $cryptType = "md5")
82
    {
92
    {
83
        switch ($cryptType) {
93
        switch ($cryptType) {
84
        case "crypt" :
94
            case "crypt" :
85
            return (($password2 == "**" . $password1) ||
-
 
86
                    (crypt($password1, $password2) == $password2)
95
                return ((string)crypt($password1, $password2) === (string)$password2);
87
                    );
-
 
88
            break;
96
                break;
89
 
-
 
90
        case "none" :
97
            case "none" :
-
 
98
            case "" :
91
            return ($password1 == $password2);
99
                return ((string)$password1 === (string)$password2);
92
            break;
100
                break;
93
 
-
 
94
        case "md5" :
101
            case "md5" :
95
            return (md5($password1) == $password2);
102
                return ((string)md5($password1) === (string)$password2);
96
            break;
103
                break;
97
 
-
 
98
        default :
104
            default :
99
            if (function_exists($cryptType)) {
105
                if (function_exists($cryptType)) {
100
                return ($cryptType($password1) == $password2);
106
                    return ((string)$cryptType($password1) === (string)$password2);
101
            }
-
 
102
            else if (method_exists($this,$cryptType)) { 
107
                } elseif (method_exists($this,$cryptType)) { 
103
                return ($this->$cryptType($password1) == $password2);
108
                    return ((string)$this->$cryptType($password1) === (string)$password2);
104
            } else {
109
                } else {
105
                return false;
110
                    return false;
106
            }
111
                }
107
            break;
112
                break;
108
        }
113
        }
109
    }
114
    }
Line 110... Line 115...
110
 
115
 
-
 
116
    // }}}
-
 
117
    // {{{ supportsChallengeResponse()
-
 
118
    
-
 
119
    /**
-
 
120
      * Returns true if the container supports Challenge Response 
-
 
121
      * password authentication
-
 
122
      */
-
 
123
    function supportsChallengeResponse()
-
 
124
    {
-
 
125
        return(false);
-
 
126
    }
-
 
127
 
-
 
128
    // }}}
-
 
129
    // {{{ getCryptType()
-
 
130
    
-
 
131
    /**
-
 
132
      * Returns the crypt current crypt type of the container
-
 
133
      *
-
 
134
      * @return string
-
 
135
      */
-
 
136
    function getCryptType()
-
 
137
    {
-
 
138
        return('');
-
 
139
    }
-
 
140
 
111
    // }}}
141
    // }}}
Line 112... Line 142...
112
    // {{{ listUsers()
142
    // {{{ listUsers()
113
 
143
 
114
    /**
144
    /**
115
     * List all users that are available from the storage container
145
     * List all users that are available from the storage container
116
     */
146
     */
117
    function listUsers()
147
    function listUsers()
118
    {
148
    {
Line -... Line 149...
-
 
149
        return AUTH_METHOD_NOT_SUPPORTED;
-
 
150
    }
-
 
151
 
119
        return AUTH_METHOD_NOT_SUPPORTED;
152
    // }}}
120
    }
153
    // {{{ getUser()
121
 
154
 
122
    /**
155
    /**
123
     * Returns a user assoc array
156
     * Returns a user assoc array
Line 128... Line 161...
128
     */
161
     */
129
    function getUser($username)
162
    function getUser($username)
130
    {
163
    {
131
        $users = $this->listUsers();
164
        $users = $this->listUsers();
132
        if($users === AUTH_METHOD_NOT_SUPPORTED){
165
        if ($users === AUTH_METHOD_NOT_SUPPORTED) {
133
            return(AUTH_METHOD_NOT_SUPPORTED);
166
            return AUTH_METHOD_NOT_SUPPORTED;
134
        }
167
        }
135
        for($i=0;$c = count($users),$i<$c;$i++){
168
        for ($i=0; $c = count($users), $i<$c; $i++) {
136
            if($users[$i]['username'] == $username){
169
            if ($users[$i]['username'] == $username) {
137
                return($users[$i]);
170
                return $users[$i];
138
            }
171
            }
139
        }
172
        }
140
        return(false);
173
        return false;
141
        
-
 
142
    }
174
    }
Line 143... Line 175...
143
 
175
 
144
    // }}}
176
    // }}}
Line 170... Line 202...
170
    {
202
    {
171
        return AUTH_METHOD_NOT_SUPPORTED;
203
        return AUTH_METHOD_NOT_SUPPORTED;
172
    }
204
    }
Line 173... Line 205...
173
 
205
 
-
 
206
    // }}}
-
 
207
    // {{{ changePassword()
-
 
208
 
-
 
209
    /**
-
 
210
     * Change password for user in the storage container
-
 
211
     *
-
 
212
     * @param string Username
-
 
213
     * @param string The new password
-
 
214
     */
-
 
215
    function changePassword($username, $password)
-
 
216
    {
-
 
217
        return AUTH_METHOD_NOT_SUPPORTED;
-
 
218
    }
-
 
219
 
Line 174... Line 220...
174
    // }}}
220
    // }}}
-
 
221
 
175
 
222
}