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