Source for file auth.php
Documentation is available at auth.php
* Class that manages the bitweaver autentication method with additional limitations from multisites
function validate($user,$pass,$challenge,$response) {
parent::validate($user,$pass,$challenge,$response);
$this->mErrors['login'] = 'User not found';
} elseif( empty( $pass ) ) {
$this->mErrors['login'] = 'Password incorrect';
$loginVal = strtoupper( $user ); // case insensitive login
$loginCol = ' UPPER(`'. (strpos( $user, '@' ) ? 'email' : 'login'). '`)';
// first verify that the user exists
$query = "select `email`, `login`, `user_id`, `user_password` from `". BIT_DB_PREFIX. "users_users` where " . $gBitDb->convertBinary(). " $loginCol = ?";
$result = $gBitDb->query( $query, array( $loginVal ) );
if( !$result->numRows() ) {
$this->mErrors['login'] = 'User not found';
$res = $result->fetchRow();
$userId = $res['user_id'];
// TikiWiki 1.8+ uses this bizarro conglomeration of fields to get the hash. this sucks for many reasons
// next verify the password with 2 hashes methods, the old one (pass)) and the new one (login.pass;email)
// TODO - this needs cleaning up - wolff_borg
if( !$gBitSystem->isFeatureActive( 'feature_challenge' ) || empty($response) ) {
$query = "select `user_id`, `content_id`, `hash` from `". BIT_DB_PREFIX. "users_users` where " . $gBitDb->convertBinary(). " $loginCol = ? and (`hash`=? or `hash`=?)";
if ( $row = $gBitDb->getRow( $query, array( $loginVal, $hash, $hash2 ) ) ) {
// auto-update old hashes with simple and standard md5( password )
if( $row['hash'] == $hash ) {
$hashUpdate = 'hash=?, ';
$bindVars[] = $gBitSystem->getUTCTime();
$query = "update `". BIT_DB_PREFIX. "users_users` set $hashUpdate `last_login`=`current_login`, `current_login`=? where `user_id`=?";
$result = $gBitDb->query($query, $bindVars );
$query = "select `multisite_id` from `". BIT_DB_PREFIX. "multisite_content` where `content_id` = ?";
$sites = $gBitDb->getAll($query, array( $row['content_id'] ) );
// This will allow for additional by site checking in future
// Currently only a single site per user_id is allowed
foreach ( $sites as $id ) {
if ( $id['multisite_id'] == $gMultisites->mMultisiteId ) {
$this->mErrors[] = 'You are not authorized on this area of the site';
$this->mErrors[] = 'Password incorrect';
// Use challenge-reponse method
// Compare pass against md5(user,challenge,hash)
$hash = $gBitDb->getOne("select `hash` from `". BIT_DB_PREFIX. "users_users` where " . $gBitDb->convertBinary(). " $loginCol = ?", array( $user ) );
if (!isset ($_SESSION["challenge"])) {
$this->mErrors[] = 'Invalid challenge';
//print("pass: $pass user: $user hash: $hash <br/>");
//print("challenge: ".$_SESSION["challenge"]." challenge: $challenge<br/>");
//print("response : $response<br/>");
if ($response == md5( strtolower($user) . $hash . $_SESSION["challenge"]) ) {
$this->updateLastLogin( $userId );
$this->mErrors[] = 'Invalid challenge';
$this->mInfo['user_id']= $userId;
if( $gBitSystem->isPackageActive( 'multisites' ) ) {
if( $gBitSystem->isPackageActive( 'multisites' ) ) {
//$authUserInfo = array( 'login' => $instance->mInfo['login'], 'password' => $instance->mInfo['password'], 'real_name' => $instance->mInfo['real_name'], 'email' => $instance->mInfo['email'] );
if( !$u->store( $pUserHash ) ) {
|