]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/File.php
rcs_id no longer makes sense with Subversion global version number
[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 // Local Variables:
94 // mode: php
95 // tab-width: 8
96 // c-basic-offset: 4
97 // c-hanging-comment-ender-p: nil
98 // indent-tabs-mode: nil
99 // End:
100 ?>