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.
24 * Baseclass for PearDB and ADODB PassUser's
25 * Authenticate against a database, to be able to use shared users.
26 * internal: no different $DbAuthParams['dsn'] defined, or
27 * external: different $DbAuthParams['dsn']
28 * The magic is done in the symbolic SQL statements in config/config.ini, similar to
31 * We support only the SQL and ADODB backends.
32 * The other WikiDB backends (flat, cvs, dba, ...) should be used for pages,
33 * not for auth stuff. If one would like to use e.g. dba for auth, he should
34 * use PearDB (SQL) with the right $DBAuthParam['auth_dsn'].
35 * (Not supported yet, since we require SQL. SQLite would make since when
36 * it will come to PHP)
40 * Preferences are handled in the parent class _PassUser, because the
41 * previous classes may also use DB pref_select and pref_update.
43 * Flat files auth is handled by the auth method "File".
48 var $_authselect, $_authupdate, $_authcreate;
50 // This can only be called from _PassUser, because the parent class
51 // sets the auth_dbi and pref methods, before this class is initialized.
52 function _DbPassUser($UserName = '', $prefs = false)
55 if ($prefs) $this->_prefs = $prefs;
57 if (!isset($this->_prefs->_method))
58 _PassUser::_PassUser($UserName);
59 elseif (!$this->isValidName($UserName)) {
60 trigger_error(_("Invalid username."), E_USER_WARNING);
63 $this->_authmethod = 'Db';
64 //$this->getAuthDbh();
65 //$this->_auth_crypt_method = @$GLOBALS['DBAuthParams']['auth_crypt_method'];
66 $dbi =& $GLOBALS['request']->_dbi;
67 $dbtype = $dbi->getParam('dbtype');
68 if ($dbtype == 'ADODB') {
69 include_once 'lib/WikiUser/AdoDb.php';
70 if (check_php_version(5))
71 return new _AdoDbPassUser($UserName, $this->_prefs);
73 $user = new _AdoDbPassUser($UserName, $this->_prefs);
74 eval("\$this = \$user;");
77 } elseif ($dbtype == 'SQL') {
78 include_once 'lib/WikiUser/PearDb.php';
79 if (check_php_version(5))
80 return new _PearDbPassUser($UserName, $this->_prefs);
82 $user = new _PearDbPassUser($UserName, $this->_prefs);
83 eval("\$this = \$user;");
86 } elseif ($dbtype == 'PDO') {
87 include_once 'lib/WikiUser/PdoDb.php';
88 if (check_php_version(5))
89 return new _PdoDbPassUser($UserName, $this->_prefs);
91 $user = new _PdoDbPassUser($UserName, $this->_prefs);
92 eval("\$this = \$user;");
99 /* Since we properly quote the username, we allow most chars here.
100 Just " ; and ' is forbidden, max length: 48 as defined in the schema.
102 function isValidName($userid = false)
104 if (!$userid) $userid = $this->_userid;
105 if (strcspn($userid, ";'\"") != strlen($userid)) return false;
106 if (strlen($userid) > 48) return false;
110 function mayChangePass()
112 return !isset($this->_authupdate);
121 // c-hanging-comment-ender-p: nil
122 // indent-tabs-mode: nil