3 /* Copyright (C) 2004 ReiniUrban
4 * This file is part of PhpWiki. Terms and Conditions see LICENSE. (GPL2)
8 * Baseclass for PearDB and ADODB PassUser's
9 * Authenticate against a database, to be able to use shared users.
10 * internal: no different $DbAuthParams['dsn'] defined, or
11 * external: different $DbAuthParams['dsn']
12 * The magic is done in the symbolic SQL statements in config/config.ini, similar to
15 * We support only the SQL and ADODB backends.
16 * The other WikiDB backends (flat, cvs, dba, ...) should be used for pages,
17 * not for auth stuff. If one would like to use e.g. dba for auth, he should
18 * use PearDB (SQL) with the right $DBAuthParam['auth_dsn'].
19 * (Not supported yet, since we require SQL. SQLite would make since when
20 * it will come to PHP)
24 * Preferences are handled in the parent class _PassUser, because the
25 * previous classes may also use DB pref_select and pref_update.
27 * Flat files auth is handled by the auth method "File".
32 var $_authselect, $_authupdate, $_authcreate;
34 // This can only be called from _PassUser, because the parent class
35 // sets the auth_dbi and pref methods, before this class is initialized.
36 function _DbPassUser($UserName='',$prefs=false) {
38 if ($prefs) $this->_prefs = $prefs;
40 if (!isset($this->_prefs->_method))
41 _PassUser::_PassUser($UserName);
42 elseif (!$this->isValidName($UserName)) {
43 trigger_error(_("Invalid username."),E_USER_WARNING);
46 $this->_authmethod = 'Db';
47 //$this->getAuthDbh();
48 //$this->_auth_crypt_method = @$GLOBALS['DBAuthParams']['auth_crypt_method'];
49 $dbi =& $GLOBALS['request']->_dbi;
50 $dbtype = $dbi->getParam('dbtype');
51 if ($dbtype == 'ADODB') {
52 include_once("lib/WikiUser/AdoDb.php");
53 if (check_php_version(5))
54 return new _AdoDbPassUser($UserName,$this->_prefs);
56 $user = new _AdoDbPassUser($UserName,$this->_prefs);
57 eval("\$this = \$user;");
61 elseif ($dbtype == 'SQL') {
62 include_once("lib/WikiUser/PearDb.php");
63 if (check_php_version(5))
64 return new _PearDbPassUser($UserName,$this->_prefs);
66 $user = new _PearDbPassUser($UserName,$this->_prefs);
67 eval("\$this = \$user;");
71 elseif ($dbtype == 'PDO') {
72 include_once("lib/WikiUser/PdoDb.php");
73 if (check_php_version(5))
74 return new _PdoDbPassUser($UserName,$this->_prefs);
76 $user = new _PdoDbPassUser($UserName,$this->_prefs);
77 eval("\$this = \$user;");
84 /* Since we properly quote the username, we allow most chars here.
85 Just " ; and ' is forbidden, max length: 48 as defined in the schema.
87 function isValidName ($userid = false) {
88 if (!$userid) $userid = $this->_userid;
89 if (strcspn($userid, ";'\"") != strlen($userid)) return false;
90 if (strlen($userid) > 48) return false;
94 function mayChangePass() {
95 return !isset($this->_authupdate);
104 // c-hanging-comment-ender-p: nil
105 // indent-tabs-mode: nil