3 /* Copyright (C) 2004 ReiniUrban
4 * This file is part of PhpWiki. Terms and Conditions see LICENSE. (GPL2)
10 * Check users defined in a .htaccess style file
13 * Preferences are handled in _PassUser
16 var $_file, $_may_change;
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);
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');
41 function mayChangePass() {
42 return $this->_may_change;
45 function userExists() {
46 if (!$this->isValidName()) {
47 return $this->_tryNextUser();
49 $this->_authmethod = 'File';
50 if (isset($this->_file->users[$this->_userid]))
53 return $this->_tryNextUser();
56 function checkPass($submitted_password) {
57 if (!$this->isValidName()) {
58 trigger_error(_("Invalid username."),E_USER_WARNING);
59 return $this->_tryNextPass($submitted_password);
61 if (!$this->_checkPassLength($submitted_password)) {
62 return WIKIAUTH_FORBIDDEN;
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;
73 return $this->_tryNextPass($submitted_password);
76 function storePass($submitted_password) {
77 if (!$this->isValidName()) {
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);
97 // c-hanging-comment-ender-p: nil
98 // indent-tabs-mode: nil