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 public $_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 return new _AdoDbPassUser($UserName, $this->_prefs);
71 } elseif ($dbtype == 'SQL') {
72 include_once 'lib/WikiUser/PearDb.php';
73 return new _PearDbPassUser($UserName, $this->_prefs);
74 } elseif ($dbtype == 'PDO') {
75 include_once 'lib/WikiUser/PdoDb.php';
76 return new _PdoDbPassUser($UserName, $this->_prefs);
81 /* Since we properly quote the username, we allow most chars here.
82 Just " ; and ' is forbidden, max length: 48 as defined in the schema.
84 function isValidName($userid = false)
86 if (!$userid) $userid = $this->_userid;
87 if (strcspn($userid, ";'\"") != strlen($userid)) return false;
88 if (strlen($userid) > 48) return false;
92 function mayChangePass()
94 return !isset($this->_authupdate);
103 // c-hanging-comment-ender-p: nil
104 // indent-tabs-mode: nil