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 = '')
38 if (!$this->_prefs and isa($this, "_FilePassUser")) {
39 if ($prefs) $this->_prefs = $prefs;
40 if (!isset($this->_prefs->_method))
41 _PassUser::_PassUser($UserName);
43 $this->_userid = $UserName;
44 // read the .htaccess style file. We use our own copy of the standard pear class.
45 $this->_may_change = defined('AUTH_USER_FILE_STORABLE') && AUTH_USER_FILE_STORABLE;
46 if (empty($file) and defined('AUTH_USER_FILE'))
47 $file = AUTH_USER_FILE;
48 // same style as in main.php
49 include_once(dirname(__FILE__) . "/../pear/File_Passwd.php");
50 // "__PHP_Incomplete_Class"
51 if (!empty($file) or empty($this->_file) or !isa($this->_file, "File_Passwd"))
52 $this->_file = new File_Passwd($file, false, $file . '.lock');
58 function mayChangePass()
60 return $this->_may_change;
65 if (!$this->isValidName()) {
66 return $this->_tryNextUser();
68 $this->_authmethod = 'File';
69 if (isset($this->_file->users[$this->_userid]))
72 return $this->_tryNextUser();
75 function checkPass($submitted_password)
77 if (!$this->isValidName()) {
78 trigger_error(_("Invalid username."), E_USER_WARNING);
79 return $this->_tryNextPass($submitted_password);
81 if (!$this->_checkPassLength($submitted_password)) {
82 return WIKIAUTH_FORBIDDEN;
84 //include_once 'lib/pear/File_Passwd.php';
85 if ($this->_file->verifyPassword($this->_userid, $submitted_password)) {
86 $this->_authmethod = 'File';
87 $this->_level = WIKIAUTH_USER;
88 if ($this->isAdmin()) // member of the Administrators group
89 $this->_level = WIKIAUTH_ADMIN;
93 return $this->_tryNextPass($submitted_password);
96 function storePass($submitted_password)
98 if (!$this->isValidName()) {
101 if ($this->_may_change) {
102 $this->_file = new File_Passwd($this->_file->filename, true,
103 $this->_file->filename . '.lock');
104 $result = $this->_file->modUser($this->_userid, $submitted_password);
105 $this->_file->close();
106 $this->_file = new File_Passwd($this->_file->filename, false);
118 // c-hanging-comment-ender-p: nil
119 // indent-tabs-mode: nil