@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Ask them for their login information. (shows a page for the user to type |
@@ -29,8 +30,9 @@ discard block |
||
29 | 30 | global $txt, $context, $scripturl, $user_info; |
30 | 31 | |
31 | 32 | // You are already logged in, go take a tour of the boards |
32 | - if (!empty($user_info['id'])) |
|
33 | - redirectexit(); |
|
33 | + if (!empty($user_info['id'])) { |
|
34 | + redirectexit(); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | // We need to load the Login template/language file. |
36 | 38 | loadLanguage('Login'); |
@@ -57,10 +59,11 @@ discard block |
||
57 | 59 | ); |
58 | 60 | |
59 | 61 | // Set the login URL - will be used when the login process is done (but careful not to send us to an attachment). |
60 | - if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) |
|
61 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
62 | - elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) |
|
63 | - unset($_SESSION['login_url']); |
|
62 | + if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) { |
|
63 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
64 | + } elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) { |
|
65 | + unset($_SESSION['login_url']); |
|
66 | + } |
|
64 | 67 | |
65 | 68 | // Create a one time token. |
66 | 69 | createToken('login'); |
@@ -83,8 +86,9 @@ discard block |
||
83 | 86 | global $cookiename, $modSettings, $context, $sourcedir, $maintenance; |
84 | 87 | |
85 | 88 | // Check to ensure we're forcing SSL for authentication |
86 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
87 | - fatal_lang_error('login_ssl_required'); |
|
89 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
90 | + fatal_lang_error('login_ssl_required'); |
|
91 | + } |
|
88 | 92 | |
89 | 93 | // Load cookie authentication stuff. |
90 | 94 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -102,19 +106,20 @@ discard block |
||
102 | 106 | list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
103 | 107 | |
104 | 108 | // That didn't work... Maybe it's using serialize? |
105 | - if (is_null($timeout)) |
|
106 | - list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
107 | - } |
|
108 | - elseif (isset($_SESSION['login_' . $cookiename])) |
|
109 | + if (is_null($timeout)) { |
|
110 | + list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
111 | + } |
|
112 | + } elseif (isset($_SESSION['login_' . $cookiename])) |
|
109 | 113 | { |
110 | 114 | list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
111 | 115 | |
112 | 116 | // Try for old format |
113 | - if (is_null($timeout)) |
|
114 | - list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
117 | + if (is_null($timeout)) { |
|
118 | + list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
119 | + } |
|
120 | + } else { |
|
121 | + trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
115 | 122 | } |
116 | - else |
|
117 | - trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
118 | 123 | |
119 | 124 | $user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4); |
120 | 125 | updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt'])); |
@@ -127,10 +132,11 @@ discard block |
||
127 | 132 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
128 | 133 | |
129 | 134 | // If we're preserving the cookie, reset it with updated salt |
130 | - if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) |
|
131 | - setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
132 | - else |
|
133 | - setTFACookie(-3600, 0, ''); |
|
135 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
136 | + setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
137 | + } else { |
|
138 | + setTFACookie(-3600, 0, ''); |
|
139 | + } |
|
134 | 140 | } |
135 | 141 | |
136 | 142 | setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
@@ -141,20 +147,20 @@ discard block |
||
141 | 147 | elseif (isset($_GET['sa']) && $_GET['sa'] == 'check') |
142 | 148 | { |
143 | 149 | // Strike! You're outta there! |
144 | - if ($_GET['member'] != $user_info['id']) |
|
145 | - fatal_lang_error('login_cookie_error', false); |
|
150 | + if ($_GET['member'] != $user_info['id']) { |
|
151 | + fatal_lang_error('login_cookie_error', false); |
|
152 | + } |
|
146 | 153 | |
147 | 154 | $user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])))); |
148 | 155 | |
149 | 156 | // Some whitelisting for login_url... |
150 | - if (empty($_SESSION['login_url'])) |
|
151 | - redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
152 | - elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
157 | + if (empty($_SESSION['login_url'])) { |
|
158 | + redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
159 | + } elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
153 | 160 | { |
154 | 161 | unset ($_SESSION['login_url']); |
155 | 162 | redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
156 | - } |
|
157 | - else |
|
163 | + } else |
|
158 | 164 | { |
159 | 165 | // Best not to clutter the session data too much... |
160 | 166 | $temp = $_SESSION['login_url']; |
@@ -165,8 +171,9 @@ discard block |
||
165 | 171 | } |
166 | 172 | |
167 | 173 | // Beyond this point you are assumed to be a guest trying to login. |
168 | - if (!$user_info['is_guest']) |
|
169 | - redirectexit(); |
|
174 | + if (!$user_info['is_guest']) { |
|
175 | + redirectexit(); |
|
176 | + } |
|
170 | 177 | |
171 | 178 | // Are you guessing with a script? |
172 | 179 | checkSession(); |
@@ -174,18 +181,21 @@ discard block |
||
174 | 181 | spamProtection('login'); |
175 | 182 | |
176 | 183 | // Set the login_url if it's not already set (but careful not to send us to an attachment). |
177 | - if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) |
|
178 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
184 | + if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) { |
|
185 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
186 | + } |
|
179 | 187 | |
180 | 188 | // Been guessing a lot, haven't we? |
181 | - if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) |
|
182 | - fatal_lang_error('login_threshold_fail', 'login'); |
|
189 | + if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) { |
|
190 | + fatal_lang_error('login_threshold_fail', 'login'); |
|
191 | + } |
|
183 | 192 | |
184 | 193 | // Set up the cookie length. (if it's invalid, just fall through and use the default.) |
185 | - if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) |
|
186 | - $modSettings['cookieTime'] = 3153600; |
|
187 | - elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) |
|
188 | - $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
194 | + if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) { |
|
195 | + $modSettings['cookieTime'] = 3153600; |
|
196 | + } elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) { |
|
197 | + $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
198 | + } |
|
189 | 199 | |
190 | 200 | loadLanguage('Login'); |
191 | 201 | // Load the template stuff. |
@@ -305,8 +315,9 @@ discard block |
||
305 | 315 | $other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd'])); |
306 | 316 | |
307 | 317 | // Snitz style - SHA-256. Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway. |
308 | - if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) |
|
309 | - $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
318 | + if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) { |
|
319 | + $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
320 | + } |
|
310 | 321 | |
311 | 322 | // phpBB3 users new hashing. We now support it as well ;). |
312 | 323 | $other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']); |
@@ -326,27 +337,29 @@ discard block |
||
326 | 337 | // Some common md5 ones. |
327 | 338 | $other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']); |
328 | 339 | $other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']); |
329 | - } |
|
330 | - elseif (strlen($user_settings['passwd']) == 40) |
|
340 | + } elseif (strlen($user_settings['passwd']) == 40) |
|
331 | 341 | { |
332 | 342 | // Maybe they are using a hash from before the password fix. |
333 | 343 | // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 |
334 | 344 | $other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd'])); |
335 | 345 | |
336 | 346 | // BurningBoard3 style of hashing. |
337 | - if (!empty($modSettings['enable_password_conversion'])) |
|
338 | - $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
347 | + if (!empty($modSettings['enable_password_conversion'])) { |
|
348 | + $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
349 | + } |
|
339 | 350 | |
340 | 351 | // Perhaps we converted to UTF-8 and have a valid password being hashed differently. |
341 | 352 | if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8') |
342 | 353 | { |
343 | 354 | // Try iconv first, for no particular reason. |
344 | - if (function_exists('iconv')) |
|
345 | - $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
355 | + if (function_exists('iconv')) { |
|
356 | + $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
357 | + } |
|
346 | 358 | |
347 | 359 | // Say it aint so, iconv failed! |
348 | - if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) |
|
349 | - $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
360 | + if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { |
|
361 | + $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
362 | + } |
|
350 | 363 | } |
351 | 364 | } |
352 | 365 | |
@@ -376,8 +389,9 @@ discard block |
||
376 | 389 | $_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1; |
377 | 390 | |
378 | 391 | // Hmm... don't remember it, do you? Here, try the password reminder ;). |
379 | - if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) |
|
380 | - redirectexit('action=reminder'); |
|
392 | + if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) { |
|
393 | + redirectexit('action=reminder'); |
|
394 | + } |
|
381 | 395 | // We'll give you another chance... |
382 | 396 | else |
383 | 397 | { |
@@ -388,8 +402,7 @@ discard block |
||
388 | 402 | return; |
389 | 403 | } |
390 | 404 | } |
391 | - } |
|
392 | - elseif (!empty($user_settings['passwd_flood'])) |
|
405 | + } elseif (!empty($user_settings['passwd_flood'])) |
|
393 | 406 | { |
394 | 407 | // Let's be sure they weren't a little hacker. |
395 | 408 | validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true); |
@@ -406,8 +419,9 @@ discard block |
||
406 | 419 | } |
407 | 420 | |
408 | 421 | // Check their activation status. |
409 | - if (!checkActivation()) |
|
410 | - return; |
|
422 | + if (!checkActivation()) { |
|
423 | + return; |
|
424 | + } |
|
411 | 425 | |
412 | 426 | DoLogin(); |
413 | 427 | } |
@@ -419,8 +433,9 @@ discard block |
||
419 | 433 | { |
420 | 434 | global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl; |
421 | 435 | |
422 | - if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) |
|
423 | - fatal_lang_error('no_access', false); |
|
436 | + if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) { |
|
437 | + fatal_lang_error('no_access', false); |
|
438 | + } |
|
424 | 439 | |
425 | 440 | loadLanguage('Profile'); |
426 | 441 | require_once($sourcedir . '/Class-TOTP.php'); |
@@ -428,8 +443,9 @@ discard block |
||
428 | 443 | $member = $context['tfa_member']; |
429 | 444 | |
430 | 445 | // Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA |
431 | - if (time() - $member['last_login'] < 120) |
|
432 | - fatal_lang_error('tfa_wait', false); |
|
446 | + if (time() - $member['last_login'] < 120) { |
|
447 | + fatal_lang_error('tfa_wait', false); |
|
448 | + } |
|
433 | 449 | |
434 | 450 | $totp = new \TOTP\Auth($member['tfa_secret']); |
435 | 451 | $totp->setRange(1); |
@@ -443,8 +459,9 @@ discard block |
||
443 | 459 | if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup'])) |
444 | 460 | { |
445 | 461 | // Check to ensure we're forcing SSL for authentication |
446 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
447 | - fatal_lang_error('login_ssl_required'); |
|
462 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
463 | + fatal_lang_error('login_ssl_required'); |
|
464 | + } |
|
448 | 465 | |
449 | 466 | $code = $_POST['tfa_code']; |
450 | 467 | |
@@ -454,20 +471,19 @@ discard block |
||
454 | 471 | |
455 | 472 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve'])); |
456 | 473 | redirectexit(); |
457 | - } |
|
458 | - else |
|
474 | + } else |
|
459 | 475 | { |
460 | 476 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
461 | 477 | |
462 | 478 | $context['tfa_error'] = true; |
463 | 479 | $context['tfa_value'] = $_POST['tfa_code']; |
464 | 480 | } |
465 | - } |
|
466 | - elseif (!empty($_POST['tfa_backup'])) |
|
481 | + } elseif (!empty($_POST['tfa_backup'])) |
|
467 | 482 | { |
468 | 483 | // Check to ensure we're forcing SSL for authentication |
469 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
470 | - fatal_lang_error('login_ssl_required'); |
|
484 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
485 | + fatal_lang_error('login_ssl_required'); |
|
486 | + } |
|
471 | 487 | |
472 | 488 | $backup = $_POST['tfa_backup']; |
473 | 489 | |
@@ -481,8 +497,7 @@ discard block |
||
481 | 497 | )); |
482 | 498 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
483 | 499 | redirectexit('action=profile;area=tfasetup;backup'); |
484 | - } |
|
485 | - else |
|
500 | + } else |
|
486 | 501 | { |
487 | 502 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
488 | 503 | |
@@ -505,8 +520,9 @@ discard block |
||
505 | 520 | { |
506 | 521 | global $context, $txt, $scripturl, $user_settings, $modSettings; |
507 | 522 | |
508 | - if (!isset($context['login_errors'])) |
|
509 | - $context['login_errors'] = array(); |
|
523 | + if (!isset($context['login_errors'])) { |
|
524 | + $context['login_errors'] = array(); |
|
525 | + } |
|
510 | 526 | |
511 | 527 | // What is the true activation status of this account? |
512 | 528 | $activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated']; |
@@ -518,8 +534,9 @@ discard block |
||
518 | 534 | return false; |
519 | 535 | } |
520 | 536 | // Awaiting approval still? |
521 | - elseif ($activation_status == 3) |
|
522 | - fatal_lang_error('still_awaiting_approval', 'user'); |
|
537 | + elseif ($activation_status == 3) { |
|
538 | + fatal_lang_error('still_awaiting_approval', 'user'); |
|
539 | + } |
|
523 | 540 | // Awaiting deletion, changed their mind? |
524 | 541 | elseif ($activation_status == 4) |
525 | 542 | { |
@@ -527,8 +544,7 @@ discard block |
||
527 | 544 | { |
528 | 545 | updateMemberData($user_settings['id_member'], array('is_activated' => 1)); |
529 | 546 | updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
530 | - } |
|
531 | - else |
|
547 | + } else |
|
532 | 548 | { |
533 | 549 | $context['disable_login_hashing'] = true; |
534 | 550 | $context['login_errors'][] = $txt['awaiting_delete_account']; |
@@ -568,8 +584,9 @@ discard block |
||
568 | 584 | setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
569 | 585 | |
570 | 586 | // Reset the login threshold. |
571 | - if (isset($_SESSION['failed_login'])) |
|
572 | - unset($_SESSION['failed_login']); |
|
587 | + if (isset($_SESSION['failed_login'])) { |
|
588 | + unset($_SESSION['failed_login']); |
|
589 | + } |
|
573 | 590 | |
574 | 591 | $user_info['is_guest'] = false; |
575 | 592 | $user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']); |
@@ -591,16 +608,18 @@ discard block |
||
591 | 608 | 'id_member' => $user_info['id'], |
592 | 609 | ) |
593 | 610 | ); |
594 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
595 | - $_SESSION['first_login'] = true; |
|
596 | - else |
|
597 | - unset($_SESSION['first_login']); |
|
611 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
612 | + $_SESSION['first_login'] = true; |
|
613 | + } else { |
|
614 | + unset($_SESSION['first_login']); |
|
615 | + } |
|
598 | 616 | $smcFunc['db_free_result']($request); |
599 | 617 | |
600 | 618 | // You've logged in, haven't you? |
601 | 619 | $update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']); |
602 | - if (empty($user_settings['tfa_secret'])) |
|
603 | - $update['last_login'] = time(); |
|
620 | + if (empty($user_settings['tfa_secret'])) { |
|
621 | + $update['last_login'] = time(); |
|
622 | + } |
|
604 | 623 | updateMemberData($user_info['id'], $update); |
605 | 624 | |
606 | 625 | // Get rid of the online entry for that old guest.... |
@@ -614,8 +633,8 @@ discard block |
||
614 | 633 | $_SESSION['log_time'] = 0; |
615 | 634 | |
616 | 635 | // Log this entry, only if we have it enabled. |
617 | - if (!empty($modSettings['loginHistoryDays'])) |
|
618 | - $smcFunc['db_insert']('insert', |
|
636 | + if (!empty($modSettings['loginHistoryDays'])) { |
|
637 | + $smcFunc['db_insert']('insert', |
|
619 | 638 | '{db_prefix}member_logins', |
620 | 639 | array( |
621 | 640 | 'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet', |
@@ -627,13 +646,15 @@ discard block |
||
627 | 646 | 'id_member', 'time' |
628 | 647 | ) |
629 | 648 | ); |
649 | + } |
|
630 | 650 | |
631 | 651 | // Just log you back out if it's in maintenance mode and you AREN'T an admin. |
632 | - if (empty($maintenance) || allowedTo('admin_forum')) |
|
633 | - redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
634 | - else |
|
635 | - redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
636 | -} |
|
652 | + if (empty($maintenance) || allowedTo('admin_forum')) { |
|
653 | + redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
654 | + } else { |
|
655 | + redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
656 | + } |
|
657 | + } |
|
637 | 658 | |
638 | 659 | /** |
639 | 660 | * Logs the current user out of their account. |
@@ -649,13 +670,15 @@ discard block |
||
649 | 670 | global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings; |
650 | 671 | |
651 | 672 | // Make sure they aren't being auto-logged out. |
652 | - if (!$internal) |
|
653 | - checkSession('get'); |
|
673 | + if (!$internal) { |
|
674 | + checkSession('get'); |
|
675 | + } |
|
654 | 676 | |
655 | 677 | require_once($sourcedir . '/Subs-Auth.php'); |
656 | 678 | |
657 | - if (isset($_SESSION['pack_ftp'])) |
|
658 | - $_SESSION['pack_ftp'] = null; |
|
679 | + if (isset($_SESSION['pack_ftp'])) { |
|
680 | + $_SESSION['pack_ftp'] = null; |
|
681 | + } |
|
659 | 682 | |
660 | 683 | // It won't be first login anymore. |
661 | 684 | unset($_SESSION['first_login']); |
@@ -683,8 +706,9 @@ discard block |
||
683 | 706 | |
684 | 707 | // And some other housekeeping while we're at it. |
685 | 708 | $salt = substr(md5(mt_rand()), 0, 4); |
686 | - if (!empty($user_info['id'])) |
|
687 | - updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
709 | + if (!empty($user_info['id'])) { |
|
710 | + updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
711 | + } |
|
688 | 712 | |
689 | 713 | if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa'])) |
690 | 714 | { |
@@ -693,10 +717,11 @@ discard block |
||
693 | 717 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
694 | 718 | |
695 | 719 | // If we're preserving the cookie, reset it with updated salt |
696 | - if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) |
|
697 | - setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
698 | - else |
|
699 | - setTFACookie(-3600, 0, ''); |
|
720 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
721 | + setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
722 | + } else { |
|
723 | + setTFACookie(-3600, 0, ''); |
|
724 | + } |
|
700 | 725 | } |
701 | 726 | |
702 | 727 | session_destroy(); |
@@ -704,14 +729,13 @@ discard block |
||
704 | 729 | // Off to the merry board index we go! |
705 | 730 | if ($redirect) |
706 | 731 | { |
707 | - if (empty($_SESSION['logout_url'])) |
|
708 | - redirectexit('', $context['server']['needs_login_fix']); |
|
709 | - elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
732 | + if (empty($_SESSION['logout_url'])) { |
|
733 | + redirectexit('', $context['server']['needs_login_fix']); |
|
734 | + } elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
710 | 735 | { |
711 | 736 | unset ($_SESSION['logout_url']); |
712 | 737 | redirectexit(); |
713 | - } |
|
714 | - else |
|
738 | + } else |
|
715 | 739 | { |
716 | 740 | $temp = $_SESSION['logout_url']; |
717 | 741 | unset($_SESSION['logout_url']); |
@@ -744,8 +768,9 @@ discard block |
||
744 | 768 | function phpBB3_password_check($passwd, $passwd_hash) |
745 | 769 | { |
746 | 770 | // Too long or too short? |
747 | - if (strlen($passwd_hash) != 34) |
|
748 | - return; |
|
771 | + if (strlen($passwd_hash) != 34) { |
|
772 | + return; |
|
773 | + } |
|
749 | 774 | |
750 | 775 | // Range of characters allowed. |
751 | 776 | $range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
@@ -756,8 +781,9 @@ discard block |
||
756 | 781 | $salt = substr($passwd_hash, 4, 8); |
757 | 782 | |
758 | 783 | $hash = md5($salt . $passwd, true); |
759 | - for (; $count != 0; --$count) |
|
760 | - $hash = md5($hash . $passwd, true); |
|
784 | + for (; $count != 0; --$count) { |
|
785 | + $hash = md5($hash . $passwd, true); |
|
786 | + } |
|
761 | 787 | |
762 | 788 | $output = substr($passwd_hash, 0, 12); |
763 | 789 | $i = 0; |
@@ -766,21 +792,25 @@ discard block |
||
766 | 792 | $value = ord($hash[$i++]); |
767 | 793 | $output .= $range[$value & 0x3f]; |
768 | 794 | |
769 | - if ($i < 16) |
|
770 | - $value |= ord($hash[$i]) << 8; |
|
795 | + if ($i < 16) { |
|
796 | + $value |= ord($hash[$i]) << 8; |
|
797 | + } |
|
771 | 798 | |
772 | 799 | $output .= $range[($value >> 6) & 0x3f]; |
773 | 800 | |
774 | - if ($i++ >= 16) |
|
775 | - break; |
|
801 | + if ($i++ >= 16) { |
|
802 | + break; |
|
803 | + } |
|
776 | 804 | |
777 | - if ($i < 16) |
|
778 | - $value |= ord($hash[$i]) << 16; |
|
805 | + if ($i < 16) { |
|
806 | + $value |= ord($hash[$i]) << 16; |
|
807 | + } |
|
779 | 808 | |
780 | 809 | $output .= $range[($value >> 12) & 0x3f]; |
781 | 810 | |
782 | - if ($i++ >= 16) |
|
783 | - break; |
|
811 | + if ($i++ >= 16) { |
|
812 | + break; |
|
813 | + } |
|
784 | 814 | |
785 | 815 | $output .= $range[($value >> 18) & 0x3f]; |
786 | 816 | } |
@@ -812,8 +842,9 @@ discard block |
||
812 | 842 | require_once($sourcedir . '/Subs-Auth.php'); |
813 | 843 | setLoginCookie(-3600, 0); |
814 | 844 | |
815 | - if (isset($_SESSION['login_' . $cookiename])) |
|
816 | - unset($_SESSION['login_' . $cookiename]); |
|
845 | + if (isset($_SESSION['login_' . $cookiename])) { |
|
846 | + unset($_SESSION['login_' . $cookiename]); |
|
847 | + } |
|
817 | 848 | } |
818 | 849 | |
819 | 850 | // We need a member! |
@@ -827,8 +858,9 @@ discard block |
||
827 | 858 | } |
828 | 859 | |
829 | 860 | // Right, have we got a flood value? |
830 | - if ($password_flood_value !== false) |
|
831 | - @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
861 | + if ($password_flood_value !== false) { |
|
862 | + @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
863 | + } |
|
832 | 864 | |
833 | 865 | // Timestamp or number of tries invalid? |
834 | 866 | if (empty($number_tries) || empty($time_stamp)) |
@@ -844,15 +876,17 @@ discard block |
||
844 | 876 | $number_tries = $time_stamp < time() - 20 ? 2 : $number_tries; |
845 | 877 | |
846 | 878 | // They are trying too fast, make them wait longer |
847 | - if ($time_stamp < time() - 10) |
|
848 | - $time_stamp = time(); |
|
879 | + if ($time_stamp < time() - 10) { |
|
880 | + $time_stamp = time(); |
|
881 | + } |
|
849 | 882 | } |
850 | 883 | |
851 | 884 | $number_tries++; |
852 | 885 | |
853 | 886 | // Broken the law? |
854 | - if ($number_tries > 5) |
|
855 | - fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
887 | + if ($number_tries > 5) { |
|
888 | + fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
889 | + } |
|
856 | 890 | |
857 | 891 | // Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it! |
858 | 892 | updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries)); |