• 0
  • 1 RepliesReplies
  • 7723 ReadTimes Read
  • 0 PointsPoints

Topic: Remember Position After Login/Logout - ENotify

no avatar
Usuario: Oskar
Rango: Recién Llegado
Mensajes: 12
Points: 0
Perfil: View Profile
Remember Position After Login/Logout - ENotify
December 17, 2010 - 04:08 04:08
Instale ENotify y dejo funcionar, alguien sabe la razón y me puedan ayudar a solucionarlo.

Code: [Select]
Encontrar[Seleccionar]

if (empty($_SESSION['login_url']))
redirectexit();
Reemplazar[Seleccionar]

if (empty($_SESSION['login_url']))
{
//Let's see if the REFERER is empty if it's no, take the next step
if (!empty($_SERVER['HTTP_REFERER']))
{
//verify if we are in the login page or some other place.
if ($_SERVER['HTTP_REFERER']==$boardurl.'/index.php?action=login' or $_SERVER['HTTP_REFERER']==$boardurl.'/login/')
{
redirectexit(); //Let's go to the main page!
}
else
{
redirectexit($_SERVER['HTTP_REFERER']); //Go back to the page where we login
}
}
else
{
redirectexit(); //There's no HTTP_REFERER, go to the main page.
}
}

LogInOut.php
Code: [Select]
<?php
/**********************************************************************************
* LogInOut.php                                                                    *
***********************************************************************************
* SMF: Simple Machines Forum                                                      *
* Open-Source Project Inspired by Zef Hemel (zef@zefhemel.com)                    *
* =============================================================================== *
* Software Version:           SMF 2.0 RC4                                         *
* Software by:                Simple Machines (http://www.simplemachines.org)     *
* Copyright 2006-2010 by:     Simple Machines LLC (http://www.simplemachines.org) *
*           2001-2006 by:     Lewis Media (http://www.lewismedia.com)             *
* Support, News, Updates at:  http://www.simplemachines.org                       *
***********************************************************************************
* This program is free software; you may redistribute it and/or modify it under   *
* the terms of the provided license as published by Simple Machines LLC.          *
*                                                                                 *
* This program is distributed in the hope that it is and will be useful, but      *
* WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY    *
* or FITNESS FOR A PARTICULAR PURPOSE.                                            *
*                                                                                 *
* See the "license.txt" file for details of the Simple Machines license.          *
* The latest version can always be found at http://www.simplemachines.org.        *
**********************************************************************************/

if (!defined(&#39;SMF&#39;))
die(&#39;Hacking attempt...&#39;);

/* This file is concerned pretty entirely, as you see from its name, with
logging in and out members, and the validation of that.  It contains:

void Login()
- shows a page for the user to type in their username and password.
- caches the referring URL in $_SESSION[&#39;login_url&#39;].
- uses the Login template and language file with the login sub
  template.
- if you are using a wireless device, uses the protocol_login sub
  template in the Wireless template.
- accessed from ?action=login.

void Login2()
- actually logs you in and checks that login was successful.
- employs protection against a specific IP or user trying to brute
  force a login to an account.
- on error, uses the same templates Login() uses.
- upgrades password encryption on login, if necessary.
- after successful login, redirects you to $_SESSION[&#39;login_url&#39;].
- accessed from ?action=login2, by forms.

void Logout(bool internal = false)
- logs the current user out of their account.
- requires that the session hash is sent as well, to prevent automatic
  logouts by images or javascript.
- doesn&#39;t check the session if internal is true.
- redirects back to $_SESSION[&#39;logout_url&#39;], if it exists.
- accessed via ?action=logout;session_var=...

string md5_hmac(string data, string key)
- old style SMF 1.0.x/YaBB SE 1.5.x hashing.
- returns the HMAC MD5 of data with key.

string phpBB3_password_check(string passwd, string passwd_hash)
- custom encryption for phpBB3 based passwords.

void validatePasswordFlood(id_member, password_flood_value = false, was_correct = false)
- this function helps protect against brute force attacks on a member&#39;s password.
*/

// Ask them for their login information.
function Login()
{
global $txt$context$scripturl;

// In wireless?  If so, use the correct sub template.
if (WIRELESS)
$context[&#39;sub_template&#39;] = WIRELESS_PROTOCOL . &#39;_login&#39;;
// Otherwise, we need to load the Login template/language file.
else
{
loadLanguage(&#39;Login&#39;);
loadTemplate(&#39;Login&#39;);
$context[&#39;sub_template&#39;] = &#39;login&#39;;
}

// Get the template ready.... not really much else to do.
$context[&#39;page_title&#39;] = $txt[&#39;login&#39;];
$context[&#39;default_username&#39;] = &$_REQUEST[&#39;u&#39;];
$context[&#39;default_password&#39;] = &#39;&#39;;
$context[&#39;never_expire&#39;] = false;

// Add the login chain to the link tree.
$context[&#39;linktree&#39;][] = array(
&#39;url&#39; => $scripturl . &#39;?action=login&#39;,
&#39;name&#39; => $txt[&#39;login&#39;],
);

// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
if (isset($_SESSION[&#39;old_url&#39;]) && strpos($_SESSION[&#39;old_url&#39;], &#39;dlattach&#39;) === false && preg_match(&#39;~(board|topic)[=,]~&#39;, $_SESSION[&#39;old_url&#39;]) != 0)
$_SESSION[&#39;login_url&#39;] = $_SESSION[&#39;old_url&#39;];
else
unset($_SESSION[&#39;login_url&#39;]);
}

// Perform the actual logging-in.
function Login2()
{
global $txt$scripturl$user_info$user_settings$smcFunc;
global $cookiename$maintenance$modSettings$context$sc$sourcedir;

// Load cookie authentication stuff.
require_once($sourcedir . &#39;/Subs-Auth.php&#39;);

if (isset($_GET[&#39;sa&#39;]) && $_GET[&#39;sa&#39;] == &#39;salt&#39; && !$user_info[&#39;is_guest&#39;])
{
if (isset($_COOKIE[$cookiename]) && preg_match(&#39;~^a:[34]:\{i:0;(i:\d{1,6}|s:[1-8]:"\d{1,8}");i:1;s:(0|40):"([a-fA-F0-9]{40})?";i:2;[id]:\d{1,14};(i:3;i:\d;)?\}$~&#39;, $_COOKIE[$cookiename]) === 1)
list (, , $timeout) = @unserialize($_COOKIE[$cookiename]);
elseif (isset($_SESSION[&#39;login_&#39; . $cookiename]))
list (, , $timeout) = @unserialize($_SESSION[&#39;login_&#39; . $cookiename]);
else
trigger_error(&#39;Login2(): Cannot be logged in without a session or cookie&#39;, E_USER_ERROR);

$user_settings[&#39;password_salt&#39;] = substr(md5(mt_rand()), 0, 4);
updateMemberData($user_info[&#39;id&#39;], array(&#39;password_salt&#39; => $user_settings[&#39;password_salt&#39;]));

setLoginCookie($timeout time(), $user_info[&#39;id&#39;], sha1($user_settings[&#39;passwd&#39;] . $user_settings[&#39;password_salt&#39;]));

redirectexit(&#39;action=login2;sa=check;member=&#39; . $user_info[&#39;id&#39;], $context[&#39;server&#39;][&#39;needs_login_fix&#39;]);
}
// Double check the cookie...
elseif (isset($_GET[&#39;sa&#39;]) && $_GET[&#39;sa&#39;] == &#39;check&#39;)
{
// Strike!  You&#39;re outta there!
if ($_GET[&#39;member&#39;] != $user_info[&#39;id&#39;])
fatal_lang_error(&#39;login_cookie_error&#39;, false);

// Some whitelisting for login_url...
if ((!empty($_SESSION[&#39;login_url&#39;]) && strpos($_SESSION[&#39;login_url&#39;], &#39;enotify&#39;)) || empty($_SESSION[&#39;login_url&#39;]))
{
//Let&#39;s see if the REFERER is empty if it&#39;s no, take the next step
if (!empty($_SERVER[&#39;HTTP_REFERER&#39;]))
{
//verify if we are in the login page or some other place.
if ($_SERVER[&#39;HTTP_REFERER&#39;]==$boardurl.&#39;/index.php?action=login&#39; or $_SERVER[&#39;HTTP_REFERER&#39;]==$boardurl.&#39;/login/&#39;)
{
redirectexit(); //Let&#39;s go to the main page!
}
else
{
redirectexit($_SERVER[&#39;HTTP_REFERER&#39;]); //Go back to the page where we login
}
}
else
{
redirectexit(); //There&#39;s no HTTP_REFERER, go to the main page.
}
}
else
{
// Best not to clutter the session data too much...
$temp $_SESSION[&#39;login_url&#39;];
unset($_SESSION[&#39;login_url&#39;]);

redirectexit($temp);
}
}

// Beyond this point you are assumed to be a guest trying to login.
if (!$user_info[&#39;is_guest&#39;])
redirectexit();

// Set the login_url if it&#39;s not already set (but careful not to send us to an attachment).
if (empty($_SESSION[&#39;login_url&#39;]) && isset($_SESSION[&#39;old_url&#39;]) && strpos($_SESSION[&#39;old_url&#39;], &#39;dlattach&#39;) === false && preg_match(&#39;~(board|topic)[=,]~&#39;, $_SESSION[&#39;old_url&#39;]) != 0)
$_SESSION[&#39;login_url&#39;] = $_SESSION[&#39;old_url&#39;];

// Are you guessing with a script that doesn&#39;t keep the session id?
spamProtection(&#39;login&#39;);

// Been guessing a lot, haven&#39;t we?
if (isset($_SESSION[&#39;failed_login&#39;]) && $_SESSION[&#39;failed_login&#39;] >= $modSettings[&#39;failed_login_threshold&#39;] * 3)
fatal_lang_error(&#39;login_threshold_fail&#39;, &#39;critical&#39;);

// Set up the cookie length.  (if it&#39;s invalid, just fall through and use the default.)
if (isset($_POST[&#39;cookieneverexp&#39;]) || (!empty($_POST[&#39;cookielength&#39;]) && $_POST[&#39;cookielength&#39;] == -1))
$modSettings[&#39;cookieTime&#39;] = 3153600;
elseif (!empty($_POST[&#39;cookielength&#39;]) && ($_POST[&#39;cookielength&#39;] >= 1 || $_POST[&#39;cookielength&#39;] <= 525600))
$modSettings[&#39;cookieTime&#39;] = (int) $_POST[&#39;cookielength&#39;];

loadLanguage(&#39;Login&#39;);
// Load the template stuff - wireless or normal.
if (WIRELESS)
$context[&#39;sub_template&#39;] = WIRELESS_PROTOCOL . &#39;_login&#39;;
else
{
loadTemplate(&#39;Login&#39;);
$context[&#39;sub_template&#39;] = &#39;login&#39;;
}

// Set up the default/fallback stuff.
$context[&#39;default_username&#39;] = isset($_REQUEST[&#39;user&#39;]) ? preg_replace(&#39;~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~&#39;, &#39;&#38;#\\1;&#39;, htmlspecialchars($_REQUEST[&#39;user&#39;])) : &#39;&#39;;
$context[&#39;default_password&#39;] = &#39;&#39;;
$context[&#39;never_expire&#39;] = $modSettings[&#39;cookieTime&#39;] == 525600 || $modSettings[&#39;cookieTime&#39;] == 3153600;
$context[&#39;login_errors&#39;] = array($txt[&#39;error_occured&#39;]);
$context[&#39;page_title&#39;] = $txt[&#39;login&#39;];

// Add the login chain to the link tree.
$context[&#39;linktree&#39;][] = array(
&#39;url&#39; => $scripturl . &#39;?action=login&#39;,
&#39;name&#39; => $txt[&#39;login&#39;],
);

if (!empty($_REQUEST[&#39;openid_identifier&#39;]) && !empty($modSettings[&#39;enableOpenID&#39;]))
{
require_once($sourcedir . &#39;/Subs-OpenID.php&#39;);
if (($open_id smf_openID_validate($_REQUEST[&#39;openid_identifier&#39;])) !== &#39;no_data&#39;)
return $open_id;
}

// You forgot to type your username, dummy!
if (!isset($_REQUEST[&#39;user&#39;]) || $_REQUEST[&#39;user&#39;] == &#39;&#39;)
{
$context[&#39;login_errors&#39;] = array($txt[&#39;need_username&#39;]);
return;
}

// Hmm... maybe &#39;admin&#39; will login with no password. Uhh... NO!
if ((!isset($_POST[&#39;passwrd&#39;]) || $_POST[&#39;passwrd&#39;] == &#39;&#39;) && (!isset($_REQUEST[&#39;hash_passwrd&#39;]) || strlen($_REQUEST[&#39;hash_passwrd&#39;]) != 40))
{
$context[&#39;login_errors&#39;] = array($txt[&#39;no_password&#39;]);
return;
}

// No funky symbols either.
if (preg_match(&#39;~[<>&"\&#39;=\\\]~&#39;, preg_replace(&#39;~(&#38;#(\\d{1,7}|x[0-9a-fA-F]{1,6});)~&#39;, &#39;&#39;, $_REQUEST[&#39;user&#39;])) != 0)
{
$context[&#39;login_errors&#39;] = array($txt[&#39;error_invalid_characters_username&#39;]);
return;
}

// Are we using any sort of integration to validate the login?
if (in_array(&#39;retry&#39;, call_integration_hook(&#39;integrate_validate_login&#39;, array($_REQUEST[&#39;user&#39;], isset($_REQUEST[&#39;hash_passwrd&#39;]) && strlen($_REQUEST[&#39;hash_passwrd&#39;]) == 40 ? $_REQUEST[&#39;hash_passwrd&#39;] : null, $modSettings[&#39;cookieTime&#39;])), true))
{
$context[&#39;login_errors&#39;] = array($txt[&#39;login_hash_error&#39;]);
$context[&#39;disable_login_hashing&#39;] = true;
return;
}

// Load the data up!
$request $smcFunc[&#39;db_query&#39;](&#39;&#39;, &#39;
SELECT passwdid_memberid_grouplngfileis_activatedemail_addressadditional_groupsmember_namepassword_salt,
openid_uripasswd_flood
FROM {db_prefix}members
WHERE &#39; . ($smcFunc[&#39;db_case_sensitive&#39;] ? &#39;LOWER(member_name) = LOWER({string:user_name})&#39; : &#39;member_name = {string:user_name}&#39;) . &#39;
LIMIT 1&#39;,
array(
&#39;user_name&#39; => $smcFunc[&#39;db_case_sensitive&#39;] ? strtolower($_REQUEST[&#39;user&#39;]) : $_REQUEST[&#39;user&#39;],
)
);
// Probably mistyped or their email, try it as an email address. (member_name first, though!)
if ($smcFunc[&#39;db_num_rows&#39;]($request) == 0)
{
$smcFunc[&#39;db_free_result&#39;]($request);

$request $smcFunc[&#39;db_query&#39;](&#39;&#39;, &#39;
SELECT passwdid_memberid_grouplngfileis_activatedemail_addressadditional_groupsmember_namepassword_saltopenid_uri,
passwd_flood
FROM {db_prefix}members
WHERE email_address = {string:user_name}
LIMIT 1&#39;,
array(
&#39;user_name&#39; => $_REQUEST[&#39;user&#39;],
)
);
// Let them try again, it didn&#39;t match anything...
if ($smcFunc[&#39;db_num_rows&#39;]($request) == 0)
{
$context[&#39;login_errors&#39;] = array($txt[&#39;username_no_exist&#39;]);
return;
}
}

$user_settings $smcFunc[&#39;db_fetch_assoc&#39;]($request);
$smcFunc[&#39;db_free_result&#39;]($request);

// Figure out the password using SMF&#39;s encryption - if what they typed is right.
if (isset($_REQUEST[&#39;hash_passwrd&#39;]) && strlen($_REQUEST[&#39;hash_passwrd&#39;]) == 40)
{
// Needs upgrading?
if (strlen($user_settings[&#39;passwd&#39;]) != 40)
{
$context[&#39;login_errors&#39;] = array($txt[&#39;login_hash_error&#39;]);
$context[&#39;disable_login_hashing&#39;] = true;
unset($user_settings);
return;
}
// Challenge passed.
elseif ($_REQUEST[&#39;hash_passwrd&#39;] == sha1($user_settings[&#39;passwd&#39;] . $sc))
$sha_passwd $user_settings[&#39;passwd&#39;];
else
{
// Don&#39;t allow this!
validatePasswordFlood($user_settings[&#39;id_member&#39;], $user_settings[&#39;passwd_flood&#39;]);

$_SESSION[&#39;failed_login&#39;] = @$_SESSION[&#39;failed_login&#39;] + 1;

if ($_SESSION[&#39;failed_login&#39;] >= $modSettings[&#39;failed_login_threshold&#39;])
redirectexit(&#39;action=reminder&#39;);
else
{
log_error($txt[&#39;incorrect_password&#39;] . &#39; - <span class="remove">&#39; . $user_settings[&#39;member_name&#39;] . &#39;</span>&#39;, &#39;user&#39;);

$context[&#39;disable_login_hashing&#39;] = true;
$context[&#39;login_errors&#39;] = array($txt[&#39;incorrect_password&#39;]);
unset($user_settings);
return;
}
}
}
else
$sha_passwd sha1(strtolower($user_settings[&#39;member_name&#39;]) . un_htmlspecialchars($_POST[&#39;passwrd&#39;]));

// Bad password!  Thought you could fool the database?!
if ($user_settings[&#39;passwd&#39;] != $sha_passwd)
{
// Let&#39;s be cautious, no hacking please. thanx.
validatePasswordFlood($user_settings[&#39;id_member&#39;], $user_settings[&#39;passwd_flood&#39;]);

// Maybe we were too hasty... let&#39;s try some other authentication methods.
$other_passwords = array();

// None of the below cases will be used most of the time (because the salt is normally set.)
if ($user_settings[&#39;password_salt&#39;] == &#39;&#39;)
{
// YaBB SE, Discus, MD5 (used a lot), SHA-1 (used some), SMF 1.0.x, IkonBoard, and none at all.
$other_passwords[] = crypt($_POST[&#39;passwrd&#39;], substr($_POST[&#39;passwrd&#39;], 0, 2));
$other_passwords[] = crypt($_POST[&#39;passwrd&#39;], substr($user_settings[&#39;passwd&#39;], 0, 2));
$other_passwords[] = md5($_POST[&#39;passwrd&#39;]);
$other_passwords[] = sha1($_POST[&#39;passwrd&#39;]);
$other_passwords[] = md5_hmac($_POST[&#39;passwrd&#39;], strtolower($user_settings[&#39;member_name&#39;]));
$other_passwords[] = md5($_POST[&#39;passwrd&#39;] . strtolower($user_settings[&#39;member_name&#39;]));
$other_passwords[] = $_POST[&#39;passwrd&#39;];

// This one is a strange one... MyPHP, crypt() on the MD5 hash.
$other_passwords[] = crypt(md5($_POST[&#39;passwrd&#39;]), md5($_POST[&#39;passwrd&#39;]));

// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don&#39;t support sha256 anyway.
if (strlen($user_settings[&#39;passwd&#39;]) == 64 && function_exists(&#39;mhash&#39;) && defined(&#39;MHASH_SHA256&#39;))
$other_passwords[] = bin2hex(mhash(MHASH_SHA256$_POST[&#39;passwrd&#39;]));

// phpBB3 users new hashing.  We now support it as well ;).
$other_passwords[] = phpBB3_password_check($_POST[&#39;passwrd&#39;], $user_settings[&#39;passwd&#39;]);

// APBoard 2 Login Method.
$other_passwords[] = md5(crypt($_REQUEST[&#39;passwrd&#39;], &#39;CRYPT_MD5&#39;));
}
// The hash should be 40 if it&#39;s SHA-1, so we&#39;re safe with more here too.
elseif (strlen($user_settings[&#39;passwd&#39;]) == 32)
{
// vBulletin 3 style hashing?  Let&#39;s welcome them with open arms \o/.
$other_passwords[] = md5(md5($_POST[&#39;passwrd&#39;]) . $user_settings[&#39;password_salt&#39;]);

// Hmm.. p&#39;raps it&#39;s Invision 2 style?
$other_passwords[] = md5(md5($user_settings[&#39;password_salt&#39;]) . md5($_POST[&#39;passwrd&#39;]));

// Some common md5 ones.
$other_passwords[] = md5($user_settings[&#39;password_salt&#39;] . $_POST[&#39;passwrd&#39;]);
$other_passwords[] = md5($_POST[&#39;passwrd&#39;] . $user_settings[&#39;password_salt&#39;]);
$other_passwords[] = md5($_POST[&#39;passwrd&#39;]);
$other_passwords[] = md5(md5($_POST[&#39;passwrd&#39;]));
}
elseif (strlen($user_settings[&#39;passwd&#39;]) == 40)
{
// Maybe they are using a hash from before the password fix.
$other_passwords[] = sha1(strtolower($user_settings[&#39;member_name&#39;]) . un_htmlspecialchars($_POST[&#39;passwrd&#39;]));

// BurningBoard3 style of hashing.
$other_passwords[] = sha1($user_settings[&#39;password_salt&#39;] . sha1($user_settings[&#39;password_salt&#39;] . sha1($_REQUEST[&#39;passwrd&#39;])));

// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
if ($context[&#39;character_set&#39;] == &#39;utf8&#39; && !empty($modSettings[&#39;previousCharacterSet&#39;]) && $modSettings[&#39;previousCharacterSet&#39;] != &#39;utf8&#39;)
{
// Try iconv first, for no particular reason.
if (function_exists(&#39;iconv&#39;))
$other_passwords[&#39;iconv&#39;] = sha1(strtolower(iconv(&#39;UTF-8&#39;, $modSettings[&#39;previousCharacterSet&#39;], $user_settings[&#39;member_name&#39;])) . un_htmlspecialchars(iconv(&#39;UTF-8&#39;, $modSettings[&#39;previousCharacterSet&#39;], $_POST[&#39;passwrd&#39;])));

// Say it aint so, iconv failed!
if (empty($other_passwords[&#39;iconv&#39;]) && function_exists(&#39;mb_convert_encoding&#39;))
$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings[&#39;member_name&#39;], &#39;UTF-8&#39;, $modSettings[&#39;previousCharacterSet&#39;])) . un_htmlspecialchars(mb_convert_encoding($_POST[&#39;passwrd&#39;], &#39;UTF-8&#39;, $modSettings[&#39;previousCharacterSet&#39;])));
}
}

// SMF&#39;s sha1 function can give a funny result on Linux (Not our fault!). If we&#39;ve now got the real one let the old one be valid!
if (strpos(strtolower(PHP_OS), &#39;win&#39;) !== 0)
{
require_once($sourcedir . &#39;/Subs-Compat.php&#39;);
$other_passwords[] = sha1_smf(strtolower($user_settings[&#39;member_name&#39;]) . un_htmlspecialchars($_POST[&#39;passwrd&#39;]));
}

// Whichever encryption it was using, let&#39;s make it use SMF&#39;s now ;).
if (in_array($user_settings[&#39;passwd&#39;], $other_passwords))
{
$user_settings[&#39;passwd&#39;] = $sha_passwd;
$user_settings[&#39;password_salt&#39;] = substr(md5(mt_rand()), 0, 4);

// Update the password and set up the hash.
updateMemberData($user_settings[&#39;id_member&#39;], array(&#39;passwd&#39; => $user_settings[&#39;passwd&#39;], &#39;password_salt&#39; => $user_settings[&#39;password_salt&#39;], &#39;passwd_flood&#39; => &#39;&#39;));
}
// Okay, they for sure didn&#39;t enter the password!
else
{
// They&#39;ve messed up again - keep a count to see if they need a hand.
$_SESSION[&#39;failed_login&#39;] = @$_SESSION[&#39;failed_login&#39;] + 1;

// Hmm... don&#39;t remember it, do you?  Here, try the password reminder ;).
if ($_SESSION[&#39;failed_login&#39;] >= $modSettings[&#39;failed_login_threshold&#39;])
redirectexit(&#39;action=reminder&#39;);
// We&#39;ll give you another chance...
else
{
// Log an error so we know that it didn&#39;t go well in the error log.
log_error($txt[&#39;incorrect_password&#39;] . &#39; - <span class="remove">&#39; . $user_settings[&#39;member_name&#39;] . &#39;</span>&#39;, &#39;user&#39;);

$context[&#39;login_errors&#39;] = array($txt[&#39;incorrect_password&#39;]);
return;
}
}
}
elseif (!empty($user_settings[&#39;passwd_flood&#39;]))
{
// Let&#39;s be sure they weren&#39;t a little hacker.
validatePasswordFlood($user_settings[&#39;id_member&#39;], $user_settings[&#39;passwd_flood&#39;], true);

// If we got here then we can reset the flood counter.
updateMemberData($user_settings[&#39;id_member&#39;], array(&#39;passwd_flood&#39; => &#39;&#39;));
}

// Correct password, but they&#39;ve got no salt; fix it!
if ($user_settings[&#39;password_salt&#39;] == &#39;&#39;)
{
$user_settings[&#39;password_salt&#39;] = substr(md5(mt_rand()), 0, 4);
updateMemberData($user_settings[&#39;id_member&#39;], array(&#39;password_salt&#39; => $user_settings[&#39;password_salt&#39;]));
}

// Check their activation status.
if (!checkActivation())
return;

DoLogin();
}

function 
checkActivation()
{
global $context$txt$scripturl$user_settings$modSettings;

if (!isset($context[&#39;login_errors&#39;]))
$context[&#39;login_errors&#39;] = array();

// What is the true activation status of this account?
$activation_status $user_settings[&#39;is_activated&#39;] > 10 ? $user_settings[&#39;is_activated&#39;] - 10 : $user_settings[&#39;is_activated&#39;];

// Check if the account is activated - COPPA first...
if ($activation_status == 5)
{
$context[&#39;login_errors&#39;][] = $txt[&#39;coppa_no_concent&#39;] . &#39; <a href="&#39; . $scripturl . &#39;?action=coppa;member=&#39; . $user_settings[&#39;id_member&#39;] . &#39;">&#39; . $txt[&#39;coppa_need_more_details&#39;] . &#39;</a>&#39;;
return false;
}
// Awaiting approval still?
elseif ($activation_status == 3)
fatal_lang_error(&#39;still_awaiting_approval&#39;, &#39;user&#39;);
// Awaiting deletion, changed their mind?
elseif ($activation_status == 4)
{
if (isset($_REQUEST[&#39;undelete&#39;]))
{
updateMemberData($user_settings[&#39;id_member&#39;], array(&#39;is_activated&#39; => 1));
updateSettings(array(&#39;unapprovedMembers&#39; => ($modSettings[&#39;unapprovedMembers&#39;] > 0 ? $modSettings[&#39;unapprovedMembers&#39;] - 1 : 0)));
}
else
{
$context[&#39;disable_login_hashing&#39;] = true;
$context[&#39;login_errors&#39;][] = $txt[&#39;awaiting_delete_account&#39;];
$context[&#39;login_show_undelete&#39;] = true;
return false;
}
}
// Standard activation?
elseif ($activation_status != 1)
{
log_error($txt[&#39;activate_not_completed1&#39;] . &#39; - <span class="remove">&#39; . $user_settings[&#39;member_name&#39;] . &#39;</span>&#39;, false);

$context[&#39;login_errors&#39;][] = $txt[&#39;activate_not_completed1&#39;] . &#39; <a href="&#39; . $scripturl . &#39;?action=activate;sa=resend;u=&#39; . $user_settings[&#39;id_member&#39;] . &#39;">&#39; . $txt[&#39;activate_not_completed2&#39;] . &#39;</a>&#39;;
return false;
}
return true;
}

function 
DoLogin()
{
global $txt$scripturl$user_info$user_settings$smcFunc;
global $cookiename$maintenance$modSettings$context$sourcedir;

// Load cookie authentication stuff.
require_once($sourcedir . &#39;/Subs-Auth.php&#39;);

// Call login integration functions.
call_integration_hook(&#39;integrate_login&#39;, array($user_settings[&#39;member_name&#39;], isset($_REQUEST[&#39;hash_passwrd&#39;]) && strlen($_REQUEST[&#39;hash_passwrd&#39;]) == 40 ? $_REQUEST[&#39;hash_passwrd&#39;] : null, $modSettings[&#39;cookieTime&#39;]));

// Get ready to set the cookie...
$username $user_settings[&#39;member_name&#39;];
$user_info[&#39;id&#39;] = $user_settings[&#39;id_member&#39;];

// Bam!  Cookie set.  A session too, just in case.
setLoginCookie(60 $modSettings[&#39;cookieTime&#39;], $user_settings[&#39;id_member&#39;], sha1($user_settings[&#39;passwd&#39;] . $user_settings[&#39;password_salt&#39;]));

// Reset the login threshold.
if (isset($_SESSION[&#39;failed_login&#39;]))
unset($_SESSION[&#39;failed_login&#39;]);

$user_info[&#39;is_guest&#39;] = false;
$user_settings[&#39;additional_groups&#39;] = explode(&#39;,&#39;, $user_settings[&#39;additional_groups&#39;]);
$user_info[&#39;is_admin&#39;] = $user_settings[&#39;id_group&#39;] == 1 || in_array(1, $user_settings[&#39;additional_groups&#39;]);

// Are you banned?
is_not_banned(true);

// An administrator, set up the login so they don&#39;t have to type it again.
if ($user_info[&#39;is_admin&#39;] && isset($user_settings[&#39;openid_uri&#39;]) && empty($user_settings[&#39;openid_uri&#39;]))
{
$_SESSION[&#39;admin_time&#39;] = time();
unset($_SESSION[&#39;just_registered&#39;]);
}

// Don&#39;t stick the language or theme after this point.
unset($_SESSION[&#39;language&#39;], $_SESSION[&#39;id_theme&#39;]);

// First login?
$request $smcFunc[&#39;db_query&#39;](&#39;&#39;, &#39;
SELECT last_login
FROM {db_prefix}members
WHERE id_member = {int:id_member}
AND last_login 0&#39;,
array(
&#39;id_member&#39; => $user_info[&#39;id&#39;],
)
);
if ($smcFunc[&#39;db_num_rows&#39;]($request) == 1)
$_SESSION[&#39;first_login&#39;] = true;
else
unset($_SESSION[&#39;first_login&#39;]);
$smcFunc[&#39;db_free_result&#39;]($request);

// You&#39;ve logged in, haven&#39;t you?
updateMemberData($user_info[&#39;id&#39;], array(&#39;last_login&#39; => time(), &#39;member_ip&#39; => $user_info[&#39;ip&#39;], &#39;member_ip2&#39; => $_SERVER[&#39;BAN_CHECK_IP&#39;]));

// Get rid of the online entry for that old guest....
$smcFunc[&#39;db_query&#39;](&#39;&#39;, &#39;
DELETE FROM {db_prefix}log_online
WHERE session = {string:session}&#39;,
array(
&#39;session&#39; => &#39;ip&#39; . $user_info[&#39;ip&#39;],
)
);
$_SESSION[&#39;log_time&#39;] = 0;

// Just log you back out if it&#39;s in maintenance mode and you AREN&#39;T an admin.
if (empty($maintenance) || allowedTo(&#39;admin_forum&#39;))
redirectexit(&#39;action=login2;sa=check;member=&#39; . $user_info[&#39;id&#39;], $context[&#39;server&#39;][&#39;needs_login_fix&#39;]);
else
redirectexit(&#39;action=logout;&#39; . $context[&#39;session_var&#39;] . &#39;=&#39; . $context[&#39;session_id&#39;], $context[&#39;server&#39;][&#39;needs_login_fix&#39;]);
}

// Log the user out.
function Logout($internal false$redirect true)
{
global $sourcedir$user_info$user_settings$context$modSettings$smcFunc;

// Make sure they aren&#39;t being auto-logged out.
if (!$internal)
checkSession(&#39;get&#39;);

require_once($sourcedir . &#39;/Subs-Auth.php&#39;);

if (isset($_SESSION[&#39;pack_ftp&#39;]))
$_SESSION[&#39;pack_ftp&#39;] = null;

// They cannot be open ID verified any longer.
if (isset($_SESSION[&#39;openid&#39;]))
unset($_SESSION[&#39;openid&#39;]);

// It won&#39;t be first login anymore.
unset($_SESSION[&#39;first_login&#39;]);

// Just ensure they aren&#39;t a guest!
if (!$user_info[&#39;is_guest&#39;])
{
// Pass the logout information to integrations.
call_integration_hook(&#39;integrate_logout&#39;, array($user_settings[&#39;member_name&#39;]));

// If you log out, you aren&#39;t online anymore :P.
$smcFunc[&#39;db_query&#39;](&#39;&#39;, &#39;
DELETE FROM {db_prefix}log_online
WHERE id_member = {int:current_member}&#39;,
array(
&#39;current_member&#39; => $user_info[&#39;id&#39;],
)
);
}

$_SESSION[&#39;log_time&#39;] = 0;

// Empty the cookie! (set it in the past, and for id_member = 0)
setLoginCookie(-36000);

// Off to the merry board index we go!
if ($redirect)
{
if (empty($_SESSION[&#39;logout_url&#39;]))
redirectexit(&#39;&#39;, $context[&#39;server&#39;][&#39;needs_login_fix&#39;]);
else
{
$temp $_SESSION[&#39;logout_url&#39;];
unset($_SESSION[&#39;logout_url&#39;]);

redirectexit($temp$context[&#39;server&#39;][&#39;needs_login_fix&#39;]);
}
}
}

// MD5 Encryption used for older passwords.
function md5_hmac($data$key)
{
$key str_pad(strlen($key) <= 64 $key pack(&#39;H*&#39;, md5($key)), 64, chr(0x00));
return md5(($key str_repeat(chr(0x5c), 64)) . pack(&#39;H*&#39;, md5(($key ^ str_repeat(chr(0x36), 64)) . $data)));
}

// Special encryption used by phpBB3.
function phpBB3_password_check($passwd$passwd_hash)
{
// Too long or too short?
if (strlen($passwd_hash) != 34)
return;

// Range of characters allowed.
$range = &#39;./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&#39;;

// Tests
$strpos strpos($range$passwd_hash[3]);
$count << $strpos;
$count2 $count;
$salt substr($passwd_hash48);

// Things are done differently for PHP 5.
if (@version_compare(PHP_VERSION, &#39;5&#39;) >= 0)
{
$hash md5($salt $passwdtrue);
for (; $count != 0; --$count)
$hash md5($hash $passwdtrue);
}
else
{
$hash pack(&#39;H*&#39;, md5($salt . $passwd));
for (; $count != 0; --$count)
$hash pack(&#39;H*&#39;, md5($hash . $passwd));
}

$output substr($passwd_hash012);
$i 0;
while ($i 16)
{
$value ord($hash[$i++]);
$output .= $range[$value 0x3f];

if ($i 16)
$value |= ord($hash[$i]) << 8;

$output .= $range[($value >> 6) & 0x3f];

if ($i++ >= 16)
break;

if ($i 16)
$value |= ord($hash[$i]) << 16;

$output .= $range[($value >> 12) & 0x3f];

if ($i++ >= 16)
break;

$output .= $range[($value >> 18) & 0x3f];
}

// Return now.
return $output;
}

// This protects against brute force attacks on a member&#39;s password. Importantly even if the password was right we DON&#39;T TELL THEM!
function validatePasswordFlood($id_member$password_flood_value false$was_correct false)
{
global $smcFunc$cookiename$sourcedir;

// As this is only brute protection, we allow 5 attempts every 10 seconds.

// Destroy any session or cookie data about this member, as they validated wrong.
require_once($sourcedir . &#39;/Subs-Auth.php&#39;);

setLoginCookie(-36000);
if (isset($_SESSION[&#39;login_&#39; . $cookiename]))
unset($_SESSION[&#39;login_&#39; . $cookiename]);

// We need a member!
if (!$id_member)
{
// Redirect back!
redirectexit();

// Probably not needed, but still make sure...
fatal_lang_error(&#39;no_access&#39;, false);
}

// Right, have we got a flood value?
if ($password_flood_value !== false)
@list ($time_stamp$number_tries) = explode(&#39;|&#39;, $password_flood_value);

// Timestamp invalid or non-existent?
if (empty($number_tries) || $time_stamp < (time() - 10))
{
// If it wasn&#39;t *that* long ago, don&#39;t give them another five goes.
$number_tries = !empty($number_tries) && $time_stamp < (time() - 20) ? 0;
$time_stamp time();
}

$number_tries++;

// Broken the law?
if ($number_tries 5)
fatal_lang_error(&#39;login_threshold_brute_fail&#39;, &#39;critical&#39;);

// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
updateMemberData($id_member, array(&#39;passwd_flood&#39; => $was_correct && $number_tries == 1 ? &#39;&#39; : $time_stamp . &#39;|&#39; . $number_tries));

}

?>

Espero su ayuda, gracias de antemano!
Usuario: Papá distante
Rango: Moderador Global
Mensajes: 3504
Points: 168
Perfil: View Profile
Pais:
de
Re:Remember Position After Login/Logout - ENotify
Reply #1 December 17, 2010 - 10:07 10:07
Ninguna parte del mod Remember position existe en tu LogInOut.php, que es lo que hace el instalador del Enotify? quizás reemplaza todo el archivo completo?
 

TAGS



top

Smfsimple.com es un sitio destinado a brindar un servicio de soporte y herramientas para foros realizados con el sistema de foros gratuito simplemachines.org. Contamos con un selecto equipo de desarrolladores y conocedores del sistema, sus foros estaran en buenas manos.
This site is not affiliated with or endorsed by Simple Machines