4 * Copyright (C) 2004 ReiniUrban
6 * This file is part of PhpWiki.
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.
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.
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.
26 * Check users defined in a .htaccess style file
29 * Preferences are handled in _PassUser
32 var $_file, $_may_change;
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);
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');
57 function mayChangePass() {
58 return $this->_may_change;
61 function userExists() {
62 if (!$this->isValidName()) {
63 return $this->_tryNextUser();
65 $this->_authmethod = 'File';
66 if (isset($this->_file->users[$this->_userid]))
69 return $this->_tryNextUser();
72 function checkPass($submitted_password) {
73 if (!$this->isValidName()) {
74 trigger_error(_("Invalid username."),E_USER_WARNING);
75 return $this->_tryNextPass($submitted_password);
77 if (!$this->_checkPassLength($submitted_password)) {
78 return WIKIAUTH_FORBIDDEN;
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;
89 return $this->_tryNextPass($submitted_password);
92 function storePass($submitted_password) {
93 if (!$this->isValidName()) {
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);
113 // c-hanging-comment-ender-p: nil
114 // indent-tabs-mode: nil