3 * Copyright © 2004 Reini Urban
5 * This file is part of PhpWiki.
7 * PhpWiki is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * PhpWiki is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * SPDX-License-Identifier: GPL-2.0-or-later
25 include_once 'lib/pear/File_Passwd.php';
30 * Check users defined in a .htaccess style file
33 * Preferences are handled in _PassUser
36 public $_file, $_may_change;
38 // This can only be called from _PassUser, because the parent class
39 // sets the pref methods, before this class is initialized.
40 function __construct($UserName = '', $prefs = false, $file = '')
42 if (!$this->_prefs and is_a($this, "_FilePassUser")) {
43 if ($prefs) $this->_prefs = $prefs;
44 if (!isset($this->_prefs->_method))
45 parent::__construct($UserName);
47 $this->_userid = $UserName;
48 // read the .htaccess style file.
49 $this->_may_change = defined('AUTH_USER_FILE_STORABLE') && AUTH_USER_FILE_STORABLE;
50 if (empty($file) and defined('AUTH_USER_FILE'))
51 $file = AUTH_USER_FILE;
55 if (empty($this->_file) or !is_a($this->_file, "File_Passwd")) {
56 $this->_file = new File_Passwd($file, false, $file . '.lock');
60 function mayChangePass()
62 return $this->_may_change;
67 if (!$this->isValidName()) {
68 return $this->_tryNextUser();
70 $this->_authmethod = 'File';
71 if (isset($this->_file->users[$this->_userid]))
74 return $this->_tryNextUser();
77 function checkPass($submitted_password)
79 if (!$this->isValidName()) {
80 trigger_error(_("Invalid username."), E_USER_WARNING);
81 return $this->_tryNextPass($submitted_password);
83 if (!$this->_checkPassLength($submitted_password)) {
84 return WIKIAUTH_FORBIDDEN;
86 if ($this->_file->verifyPassword($this->_userid, $submitted_password)) {
87 $this->_authmethod = 'File';
88 $this->_level = WIKIAUTH_USER;
89 if ($this->isAdmin()) // member of the Administrators group
90 $this->_level = WIKIAUTH_ADMIN;
94 return $this->_tryNextPass($submitted_password);
97 function storePass($submitted_password)
99 if (!$this->isValidName()) {
102 if ($this->_may_change) {
103 $this->_file = new File_Passwd($this->_file->filename, true,
104 $this->_file->filename . '.lock');
105 $result = $this->_file->modUser($this->_userid, $submitted_password);
106 $this->_file->close();
107 $this->_file = new File_Passwd($this->_file->filename, false);