]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/File.php
var --> public
[SourceForge/phpwiki.git] / lib / WikiUser / File.php
1 <?php
2
3 /*
4  * Copyright (C) 2004 ReiniUrban
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 class _FilePassUser
24     extends _PassUser
25     /**
26      * Check users defined in a .htaccess style file
27      * username:crypt\n...
28      *
29      * Preferences are handled in _PassUser
30      */
31 {
32     public $_file, $_may_change;
33
34     // This can only be called from _PassUser, because the parent class
35     // sets the pref methods, before this class is initialized.
36     function _FilePassUser($UserName = '', $prefs = false, $file = '')
37     {
38         if (!$this->_prefs and isa($this, "_FilePassUser")) {
39             if ($prefs) $this->_prefs = $prefs;
40             if (!isset($this->_prefs->_method))
41                 _PassUser::_PassUser($UserName);
42         }
43         $this->_userid = $UserName;
44         // read the .htaccess style file. We use our own copy of the standard pear class.
45         $this->_may_change = defined('AUTH_USER_FILE_STORABLE') && AUTH_USER_FILE_STORABLE;
46         if (empty($file) and defined('AUTH_USER_FILE'))
47             $file = AUTH_USER_FILE;
48         // same style as in main.php
49         include_once(dirname(__FILE__) . "/../pear/File_Passwd.php");
50         // "__PHP_Incomplete_Class"
51         if (!empty($file) or empty($this->_file) or !isa($this->_file, "File_Passwd"))
52             $this->_file = new File_Passwd($file, false, $file . '.lock');
53         else
54             return false;
55         return $this;
56     }
57
58     function mayChangePass()
59     {
60         return $this->_may_change;
61     }
62
63     function userExists()
64     {
65         if (!$this->isValidName()) {
66             return $this->_tryNextUser();
67         }
68         $this->_authmethod = 'File';
69         if (isset($this->_file->users[$this->_userid]))
70             return true;
71
72         return $this->_tryNextUser();
73     }
74
75     function checkPass($submitted_password)
76     {
77         if (!$this->isValidName()) {
78             trigger_error(_("Invalid username."), E_USER_WARNING);
79             return $this->_tryNextPass($submitted_password);
80         }
81         if (!$this->_checkPassLength($submitted_password)) {
82             return WIKIAUTH_FORBIDDEN;
83         }
84         //include_once 'lib/pear/File_Passwd.php';
85         if ($this->_file->verifyPassword($this->_userid, $submitted_password)) {
86             $this->_authmethod = 'File';
87             $this->_level = WIKIAUTH_USER;
88             if ($this->isAdmin()) // member of the Administrators group
89                 $this->_level = WIKIAUTH_ADMIN;
90             return $this->_level;
91         }
92
93         return $this->_tryNextPass($submitted_password);
94     }
95
96     function storePass($submitted_password)
97     {
98         if (!$this->isValidName()) {
99             return false;
100         }
101         if ($this->_may_change) {
102             $this->_file = new File_Passwd($this->_file->filename, true,
103                 $this->_file->filename . '.lock');
104             $result = $this->_file->modUser($this->_userid, $submitted_password);
105             $this->_file->close();
106             $this->_file = new File_Passwd($this->_file->filename, false);
107             return $result;
108         }
109         return false;
110     }
111
112 }
113
114 // Local Variables:
115 // mode: php
116 // tab-width: 8
117 // c-basic-offset: 4
118 // c-hanging-comment-ender-p: nil
119 // indent-tabs-mode: nil
120 // End: