Source for file basicauth.php
Documentation is available at basicauth.php
* User Authentication object
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
/** sql manipulation routines */
require_once 'inc/formslib/sql.php';
/** type checking and data manipulation */
require_once 'inc/typeinfo.php';
/** username and password checks */
require_once 'inc/passwords.php';
require_once 'inc/permissions.php';
require_once 'inc/logging.php';
require_once 'inc/bb/configreader.php';
* @todo //TODO: update permissions system
* @todo //TODO: documentation
var $uid; //user id from table
/** @var array database row for the user */
/** @var integer debug level (0=off, 10=verbose) */
* Create the authentication object
* @param array $data array containing keys 'username' and 'pass'
* @param boolean $recheck (optional) ignore session data and check anyway
* @param string $table (optional) db table from which login data should be taken
function BasicAuth($data, $recheck =
false, $table=
'users') {
// Only start the session if one has not already been started (e.g. to cope
// with the situation where session.auto_start=1 in php.ini or where
// the entire thing is embedded within some other framework.
// For session.auto_start, the following is enough:
// if (! ini_get('session.auto_start')) {
// But we can check the session_id() (hexadecimal string if session has started
// empty string "" if it hasn't)
#print "Creating new session". session_id();;
#print "Started session, ". session_id();
if (!$recheck &&
$this->_var_get('uid') !==
NULL) {
// the we have a session login already done, check it
} elseif (isset
($data['username'])) {
// then some login info has been provided, so we need to check it
// we're not logged in at all
* Generate a pseudo-random tag that is unique to this user and installation
* The tag is unique to this user and this installation of Bumblebee so that it
* can be used to test whether the submitted data is from a Bumblebee-produced
* form or if it is perhaps from a spoofed source.
* @see http://www.debian-administration.org/articles/465
* @returns string tag unique to this user and installation
* Test if the magic tag in the form matches the magic tag for this user
* @see makeValidationTag()
* @param string $tag submitted tag to be tested
* @returns boolean the submitted tag is valid
* test function to see if user is logge in
* @returns boolean user is logged in
* log the user out of the system
* obtain an error string that (if appropriate) describes the failure mode
* @returns string error message
($conf->value('auth', 'authAdvancedSecurityHole') &&
$conf->value('auth', 'verboseFailure'))) {
// protect any additional info that is in the error string:
// functions in this class can report the error in the format 'General error: details'
// Normally, we shouldn't reveal whether it was a bad username or password,
// but for debugging purposes, it's nice to have the extra info.
* store a piece of data in the session for persistance across page calls
* @param string $var name to call the data in the session
* @param mixed $value value to store
$_SESSION[$conf->SessionIndex][$var] =
$value;
* retrieve a piece of data previously stored
* @returns mixed value stored
return issetSet($_SESSION[$conf->SessionIndex], $var);
* create the login session for persistant data storage
* @param array $row database row for the user
// $this->_var_put('email'] = $this->email = $row['email'];
// $this->_var_put('isadmin'] = $this->isadmin = $row['isadmin'];
// check that the credentials contained in the session are OK
if ($row['username'] ==
$this->_var_get('username') &&
$row['name'] ==
$this->_var_get('name') ) {
$this->email =
$row['email'];
$this->isadmin =
$row['isadmin'];
$this->_error =
T_('Login failed: SESSION INVALID!');
* check login details, if OK, set up a PHP SESSION to manage the login
* @returns boolean credentialsOK
// a login attempt must have a password
if (! isset
($data['pass']) ) {
$this->_error =
'Login failed: no password specified.';
// test the username to make sure it looks valid
$this->_error =
T_('Login failed: bad username') .
' -- '
.
T_('Either change the username using phpMyAdmin or change how you define a valid username in config/bumblebee.ini (see the value "validUserRegexp")');
// then there is data provided to us in a login form
// need to verify if it is valid login info
$PASSWORD =
$data['pass'];
$USERNAME =
$data['username'];
// if the admin user has locked themselves out of the system, let them get back in:
if ($conf->value('auth','authAdvancedSecurityHole') &&
$conf->value('auth','recoverAdminPassword')) {
// the username has to exist in the users table for the login to be valid, so check that first
if ($conf->value('auth', 'useRadius') &&
$conf->value('auth', 'RadiusPassToken') ==
$row['passwd']) {
} elseif ($conf->value('auth','useLDAP') &&
$conf->value('auth','LDAPPassToken') ==
$row['passwd']) {
} elseif ($conf->value('auth', 'useLocal')) {
} else { //system is misconfigured
$this->_error =
T_('System has no login method enabled');
if (isset
($row['suspended']) &&
$row['suspended']) {
$this->_error =
T_('Login failed: this account is suspended, please contact us about this.');
// if we got to here, then we're logged in!
if ($conf->value('auth','authAdvancedSecurityHole') &&
$conf->value('auth','recoverAdminPassword')) {
$row =
array('id' => -
1);
$this->_error =
T_('Login failed: unknown username');
//$row = db_fetch_array($sql);
* RADIUS auth method to login the user against a RADIUS server
require_once 'Auth/Auth.php';
$conf->MergeFile('radius.ini', '_auth_radius');
"servers" =>
array(array($conf->value('_auth_radius', 'host'),
$conf->value('_auth_radius', 'key'),
"authtype" =>
$conf->value('_auth_radius', 'authtype')
// start the PEAR::Auth system using RADIUS authentication with the parameters
// we have defined here for this config. Do not display a login box on error.
$a =
new Auth("RADIUS", $params, '', false);
$a->username =
$username;
$a->password =
$password;
$this->_error =
T_('Login failed: radius auth failed');
* LDAP auth method to login the user against an LDAP server
require_once 'Auth/Auth.php';
$conf->MergeFile('ldap.ini', '_auth_ldap');
'url' =>
$conf->value('_auth_ldap', 'url'),
'basedn' =>
$conf->value('_auth_ldap', 'basedn'),
'userattr' =>
$conf->value('_auth_ldap', 'userattr'),
'useroc' =>
$conf->value('_auth_ldap', 'userobjectclass'), // for v 1.2
'userfilter' =>
$conf->value('_auth_ldap', 'userfilter'), // for v 1.3
'debug' =>
$conf->value('_auth_ldap', 'debug') ?
true :
false,
'version' =>
intval($conf->value('_auth_ldap', 'version')), // for v 1.3
'start_tls' =>
$conf->value('_auth_ldap', 'start_tls') ?
true :
false // requires patched version of LDAP auth
// start the PEAR::Auth system using LDAP authentication with the parameters
// we have defined here for this config. Do not display a login box on error.
$a =
new Auth("LDAP", $params, '', false);
$a->username =
$username;
$a->password =
$password;
$this->_error =
T_('Login failed: ldap auth failed');
$this->_error =
T_('Login failed: bad password');
if ($passOK &&
$conf->value('auth', 'convertEntries', false)
return $id ==
$this->uid;
return (getenv('HTTP_X_FORWARDED_FOR')
?
getenv('HTTP_X_FORWARDED_FOR')
* @global string db table prefix
logmsg(8, "Updating password entry to new hash scheme for user {$this->user_row['id']}");
db_quiet("UPDATE {$TABLEPREFIX}users SET passwd=$enc WHERE id='{$this->user_row['id']}'
");
Documentation generated on Tue, 06 Mar 2007 10:00:39 +0000 by phpDocumentor 1.3.0