]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/File.php
fix #1191096 by Karel
[SourceForge/phpwiki.git] / lib / WikiUser / File.php
1 <?php //-*-php-*-
2 rcs_id('$Id: File.php,v 1.6 2005-05-04 05:37:34 rurban Exp $');
3 /* Copyright (C) 2004 ReiniUrban
4  * This file is part of PhpWiki. Terms and Conditions see LICENSE. (GPL2)
5  */
6
7 class _FilePassUser
8 extends _PassUser
9 /**
10  * Check users defined in a .htaccess style file
11  * username:crypt\n...
12  *
13  * Preferences are handled in _PassUser
14  */
15 {
16     var $_file, $_may_change;
17
18     // This can only be called from _PassUser, because the parent class 
19     // sets the pref methods, before this class is initialized.
20     function _FilePassUser($UserName='', $prefs=false, $file='') {
21         if (!$this->_prefs and isa($this, "_FilePassUser")) {
22             if ($prefs) $this->_prefs = $prefs;
23             if (!isset($this->_prefs->_method))
24               _PassUser::_PassUser($UserName);
25         }
26         $this->_userid = $UserName;
27         // read the .htaccess style file. We use our own copy of the standard pear class.
28         //include_once 'lib/pear/File_Passwd.php';
29         $this->_may_change = defined('AUTH_USER_FILE_STORABLE') && AUTH_USER_FILE_STORABLE;
30         if (empty($file) and defined('AUTH_USER_FILE'))
31             $file = AUTH_USER_FILE;
32         // same style as in main.php
33         include_once(dirname(__FILE__)."/../pear/File_Passwd.php"); 
34         // "__PHP_Incomplete_Class"
35         if (!empty($file) or empty($this->_file) or !isa($this->_file,"File_Passwd"))
36             $this->_file = new File_Passwd($file, false, $file.'.lock');
37         else
38             return false;
39         return $this;
40     }
41  
42     function mayChangePass() {
43         return $this->_may_change;
44     }
45
46     function userExists() {
47         if (!$this->isValidName()) {
48             return $this->_tryNextUser();
49         }
50         $this->_authmethod = 'File';
51         if (isset($this->_file->users[$this->_userid]))
52             return true;
53             
54         return $this->_tryNextUser();
55     }
56
57     function checkPass($submitted_password) {
58         if (!$this->isValidName()) {
59             trigger_error(_("Invalid username."),E_USER_WARNING);
60             return $this->_tryNextPass($submitted_password);
61         }
62         if (!$this->_checkPassLength($submitted_password)) {
63             return WIKIAUTH_FORBIDDEN;
64         }
65         //include_once 'lib/pear/File_Passwd.php';
66         if ($this->_file->verifyPassword($this->_userid, $submitted_password)) {
67             $this->_authmethod = 'File';
68             $this->_level = WIKIAUTH_USER;
69             if ($this->isAdmin()) // member of the Administrators group
70                 $this->_level = WIKIAUTH_ADMIN;
71             return $this->_level;
72         }
73         
74         return $this->_tryNextPass($submitted_password);
75     }
76
77     function storePass($submitted_password) {
78         if (!$this->isValidName()) {
79             return false;
80         }
81         if ($this->_may_change) {
82             $this->_file = new File_Passwd($this->_file->_filename, true, 
83                                            $this->_file->_filename.'.lock');
84             $result = $this->_file->modUser($this->_userid, $submitted_password);
85             $this->_file->close();
86             $this->_file = new File_Passwd($this->_file->_filename, false);
87             return $result;
88         }
89         return false;
90     }
91
92 }
93
94 // $Log: not supported by cvs2svn $
95 // Revision 1.5  2005/02/14 12:28:27  rurban
96 // fix policy strict. Thanks to Mikhail Vladimirov
97 //
98 // Revision 1.4  2004/12/26 17:11:16  rurban
99 // just copyright
100 //
101 // Revision 1.3  2004/12/20 16:05:01  rurban
102 // gettext msg unification
103 //
104 // Revision 1.2  2004/12/19 00:58:02  rurban
105 // Enforce PASSWORD_LENGTH_MINIMUM in almost all PassUser checks,
106 // Provide an errormessage if so. Just PersonalPage and BogoLogin not.
107 // Simplify httpauth logout handling and set sessions for all methods.
108 // fix main.php unknown index "x" getLevelDescription() warning.
109 //
110 // Revision 1.1  2004/11/01 10:43:58  rurban
111 // seperate PassUser methods into seperate dir (memory usage)
112 // fix WikiUser (old) overlarge data session
113 // remove wikidb arg from various page class methods, use global ->_dbi instead
114 // ...
115 //
116
117 // Local Variables:
118 // mode: php
119 // tab-width: 8
120 // c-basic-offset: 4
121 // c-hanging-comment-ender-p: nil
122 // indent-tabs-mode: nil
123 // End:
124 ?>