]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/File.php
Whitespace only
[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     var $_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         if (!$this->_prefs and isa($this, "_FilePassUser")) {
38             if ($prefs) $this->_prefs = $prefs;
39             if (!isset($this->_prefs->_method))
40               _PassUser::_PassUser($UserName);
41         }
42         $this->_userid = $UserName;
43         // read the .htaccess style file. We use our own copy of the standard pear class.
44         $this->_may_change = defined('AUTH_USER_FILE_STORABLE') && AUTH_USER_FILE_STORABLE;
45         if (empty($file) and defined('AUTH_USER_FILE'))
46             $file = AUTH_USER_FILE;
47         // same style as in main.php
48         include_once(dirname(__FILE__)."/../pear/File_Passwd.php");
49         // "__PHP_Incomplete_Class"
50         if (!empty($file) or empty($this->_file) or !isa($this->_file, "File_Passwd"))
51             $this->_file = new File_Passwd($file, false, $file.'.lock');
52         else
53             return false;
54         return $this;
55     }
56
57     function mayChangePass() {
58         return $this->_may_change;
59     }
60
61     function userExists() {
62         if (!$this->isValidName()) {
63             return $this->_tryNextUser();
64         }
65         $this->_authmethod = 'File';
66         if (isset($this->_file->users[$this->_userid]))
67             return true;
68
69         return $this->_tryNextUser();
70     }
71
72     function checkPass($submitted_password) {
73         if (!$this->isValidName()) {
74             trigger_error(_("Invalid username."),E_USER_WARNING);
75             return $this->_tryNextPass($submitted_password);
76         }
77         if (!$this->_checkPassLength($submitted_password)) {
78             return WIKIAUTH_FORBIDDEN;
79         }
80         //include_once 'lib/pear/File_Passwd.php';
81         if ($this->_file->verifyPassword($this->_userid, $submitted_password)) {
82             $this->_authmethod = 'File';
83             $this->_level = WIKIAUTH_USER;
84             if ($this->isAdmin()) // member of the Administrators group
85                 $this->_level = WIKIAUTH_ADMIN;
86             return $this->_level;
87         }
88
89         return $this->_tryNextPass($submitted_password);
90     }
91
92     function storePass($submitted_password) {
93         if (!$this->isValidName()) {
94             return false;
95         }
96         if ($this->_may_change) {
97             $this->_file = new File_Passwd($this->_file->filename, true,
98                                            $this->_file->filename.'.lock');
99             $result = $this->_file->modUser($this->_userid, $submitted_password);
100             $this->_file->close();
101             $this->_file = new File_Passwd($this->_file->filename, false);
102             return $result;
103         }
104         return false;
105     }
106
107 }
108
109 // Local Variables:
110 // mode: php
111 // tab-width: 8
112 // c-basic-offset: 4
113 // c-hanging-comment-ender-p: nil
114 // indent-tabs-mode: nil
115 // End: