$ret = $passHash;
// Is a secret key and master salt already initialized?
- //* DEBUG: */ outputHtml(__FUNCTION__.':'.intval(isExtensionInstalled('sql_patches')).'/'.intval(isConfigEntrySet('_PRIME')).'/'.intval(isConfigEntrySet('secret_key')).'/'.intval(isConfigEntrySet('master_salt')).'<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, intval(isExtensionInstalled('sql_patches')) . '/' . intval(isConfigEntrySet('_PRIME')) . '/' . intval(isConfigEntrySet('secret_key')) . '/' . intval(isConfigEntrySet('master_salt')));
if ((isExtensionInstalled('sql_patches')) && (isConfigEntrySet('_PRIME')) && (isConfigEntrySet('secret_key')) && (isConfigEntrySet('master_salt'))) {
// Only calculate when the secret key is generated
- //* DEBUG: */ outputHtml(__FUNCTION__.':'.strlen($passHash).'/'.strlen(getConfig('secret_key')).'<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash) . '/' . strlen(getConfig('secret_key')));
if ((strlen($passHash) != 49) || (strlen(getConfig('secret_key')) != 40)) {
// Both keys must have same length so return unencrypted
- logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash).'!=49/'.strlen(getConfig('secret_key')).'!=40');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash) . '!=49/' . strlen(getConfig('secret_key')) . '!=40');
return $ret;
} // END - if
$newHash = ''; $start = 9;
- //* DEBUG: */ outputHtml('passHash=' . $passHash . '(' . strlen($passHash) . ')<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'passHash=' . $passHash . '(' . strlen($passHash) . ')');
for ($idx = 0; $idx < 20; $idx++) {
$part1 = hexdec(substr($passHash, ($idx * 2) + (strlen($passHash) - strlen(getConfig('secret_key'))), 2));
$part2 = hexdec(substr(getConfig('secret_key'), $start, 2));
- //* DEBUG: */ outputHtml('part1='.$part1.'/part2='.$part2.'<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'part1=' . $part1 . '/part2=' . $part2);
$mod = dechex($idx);
if ($part1 > $part2) {
$mod = dechex(sqrt(($part1 - $part2) * getConfig('_PRIME') / pi()));
$mod = dechex(sqrt(($part2 - $part1) * getConfig('_PRIME') / pi()));
}
$mod = substr($mod, 0, 2);
- //* DEBUG: */ outputHtml('part1='.$part1.'/part2='.$part2.'/mod=' . $mod . '('.strlen($mod).')<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'part1=' . $part1 . '/part2=' . $part2 . '/mod=' . $mod . '(' . strlen($mod) . ')');
$mod = str_repeat(0, (2 - strlen($mod))) . $mod;
- //* DEBUG: */ outputHtml('mod(' . ($idx * 2) . ')=' . $mod . '*<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mod(' . ($idx * 2) . ')=' . $mod . '*');
$start += 2;
$newHash .= $mod;
} // END - for
- //* DEBUG: */ outputHtml($passHash . '<br />' . $newHash . ' (' . strlen($newHash) . ')<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $passHash . ',' . $newHash . ' (' . strlen($newHash) . ')');
$ret = generateHash($newHash, getConfig('master_salt'));
- //* DEBUG: */ outputHtml('ret=' . $ret . '<br />');
} // END - if
// Return result
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret . '');
return $ret;
}
if ((getExtensionVersion('bonus') >= '0.3.5') && (getConfig('bonus_mode') != 'ADD')) handleBonusPoints('login_bonus');
} // END - if
- // Calculate new hash with the secret key and master salt together
- $content['hash'] = encodeHashForCookie($content['hash']);
-
// @TODO Make this filter working: $URL = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON));
// Set member id
setMemberId($userid);
// Try to set session data (which shall normally always work!)
- if ((setSession('userid', $userid )) && (setSession('u_hash', $content['hash']))) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',hash=' . $content['hash'] . '(' . strlen($content['hash']) . ')');
+ if ((setSession('userid', $userid )) && (setSession('u_hash', encodeHashForCookie($content['hash'])))) {
// Update database records
SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `total_logins`=`total_logins`+1" . $add . " WHERE `userid`=%s LIMIT 1",
array($userid), __FUNCTION__, __LINE__);
// is the cache entry there?
if (isset($GLOBALS['is_member'])) {
// Then return it
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHED! (' . intval($GLOBALS['is_member']) . ')');
return $GLOBALS['is_member'];
- } elseif (getMemberId() == '0') {
+ } elseif ((!isSessionVariableSet('userid')) || (!isSessionVariableSet('u_hash'))) {
// No member
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No member set in cookie/session.');
return false;
} else {
- // Transfer userid=>current
- setCurrentUserid(getMemberId());
+ // Get it secured from session
+ setMemberId(getSession('userid'));
+ setCurrentUserId(getMemberId());
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . getSession('userid') . ' used from cookie/session.');
}
// Init user data array
$ret = true;
} else {
// Maybe got locked etc.
- logDebugMessage(__FUNCTION__, __LINE__, 'status=' . getUserData('status'));
+ //* DEBUG */ logDebugMessage(__FUNCTION__, __LINE__, 'status=' . getUserData('status') . ',' . $valPass . '(' . strlen($valPass) . ')/' . getSession('u_hash') . '(' . strlen(getSession('u_hash')) . ')/' . getUserData('password') . '(' . strlen(getUserData('password')) . ')');
destroyMemberSession();
}
} else {
// Cookie data is invalid!
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cookie data invalid or user not found.');
destroyMemberSession();
}
} else {
// Cookie data is invalid!
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cookie data not complete.');
destroyMemberSession();
}
$GLOBALS['is_member'] = $ret;
// Return status
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . intval($ret));
return $ret;
}
$ret = false;
$passCookie = '';
$valPass = '';
- //* DEBUG: */ print(__FUNCTION__.':'.$adminLogin.'<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminLogin.'<br />');
// If admin login is not given take current from cookies...
if ((empty($adminLogin)) && (isSessionVariableSet('admin_login')) && (isSessionVariableSet('admin_md5'))) {
$adminLogin = getSession('admin_login');
$passCookie = getSession('admin_md5');
} // END - if
- //* DEBUG: */ print(__FUNCTION__.':'.$adminLogin.'/'.$passCookie.'<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminLogin.'/'.$passCookie.'<br />');
// Do we have cache?
if (!isset($GLOBALS['is_admin'][$adminLogin])) {
if (!empty($valPass)) {
// Check if password is valid
- //* DEBUG: */ print(__FUNCTION__ . ':(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie).'<br />');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie));
$GLOBALS['is_admin'][$adminLogin] = (($valPass == $passCookie) || ((strlen($valPass) == 32) && ($valPass == md5($passCookie))) || (($valPass == '*FAILED*') && (!isExtensionActive('cache'))));
} // END - if
} // END - if
// Determine and set referal id
determineReferalId();
-// Transfer userid from session and validate it
-if (isSessionVariableSet('userid')) {
- // Get it secured from session
- setMemberId(getSession('userid'));
-
- // Is it valid?
- if (!isMember()) {
- // Then destroy the user id
- destroyMemberSession();
- } // END - if
-} // END - if
-
// [EOF]
?>