Commit 505d0978 by Scott

Remove some login code duplication

parent c88fb8ba
...@@ -210,16 +210,15 @@ ...@@ -210,16 +210,15 @@
else { else {
$errors = array(); $errors = array();
$legacyPassError = strtolower(qa_db_calc_passcheck($inoldpassword, $useraccount['passsalt'])) != strtolower($useraccount['passcheck']);
if (QA_PASSWORD_HASH) { if (QA_PASSWORD_HASH) {
if ( $passError = !password_verify($inoldpassword,$useraccount['passhash']);
($haspasswordold && (strtolower(qa_db_calc_passcheck($inoldpassword, $useraccount['passsalt'])) != strtolower($useraccount['passcheck']))) || if (($haspasswordold && $legacyPassError) || (!$haspasswordold && $haspassword && $passError)) {
(!$haspasswordold && $haspassword && !password_verify($inoldpassword,$useraccount['passhash']))
) {
$errors['oldpassword'] = qa_lang('users/password_wrong'); $errors['oldpassword'] = qa_lang('users/password_wrong');
} }
} else { } else {
if ($haspassword && (strtolower(qa_db_calc_passcheck($inoldpassword, $useraccount['passsalt'])) != strtolower($useraccount['passcheck']))) { if ($haspassword && $legacyPassError) {
$errors['oldpassword'] = qa_lang('users/password_wrong'); $errors['oldpassword'] = qa_lang('users/password_wrong');
} }
} }
......
...@@ -68,51 +68,40 @@ ...@@ -68,51 +68,40 @@
$inuserid=$matchusers[0]; $inuserid=$matchusers[0];
$userinfo=qa_db_select_with_pending(qa_db_user_account_selectspec($inuserid, true)); $userinfo=qa_db_select_with_pending(qa_db_user_account_selectspec($inuserid, true));
if (QA_PASSWORD_HASH) { $legacyPassOk = strtolower(qa_db_calc_passcheck($inpassword, $userinfo['passsalt'])) == strtolower($userinfo['passcheck']);
$haspassword=isset($userinfo['passhash']);
$haspasswordold=isset($userinfo['passsalt']) && isset($userinfo['passcheck']);
if ( if (QA_PASSWORD_HASH) {
($haspasswordold && strtolower(qa_db_calc_passcheck($inpassword, $userinfo['passsalt'])) == strtolower($userinfo['passcheck'])) || $haspassword = isset($userinfo['passhash']);
($haspassword && password_verify($inpassword,$userinfo['passhash'])) $haspasswordold = isset($userinfo['passsalt']) && isset($userinfo['passcheck']);
) { $passOk = password_verify($inpassword,$userinfo['passhash']);
// login and redirect
require_once QA_INCLUDE_DIR.'app/users.php';
if (($haspasswordold && $legacyPassOk) || ($haspassword && $passOk)) {
// upgrade password or rehash, when options like the cost parameter changed // upgrade password or rehash, when options like the cost parameter changed
if ($haspasswordold || password_needs_rehash($userinfo['passhash'], PASSWORD_BCRYPT)) { if ($haspasswordold || password_needs_rehash($userinfo['passhash'], PASSWORD_BCRYPT)) {
qa_db_user_set_password($inuserid, $inpassword); qa_db_user_set_password($inuserid, $inpassword);
} }
qa_set_logged_in_user($inuserid, $userinfo['handle'], !empty($inremember)); } else {
$topath=qa_get('to');
if (isset($topath))
qa_redirect_raw(qa_path_to_root().$topath); // path already provided as URL fragment
elseif ($passwordsent)
qa_redirect('account');
else
qa_redirect('');
} else
$errors['password']=qa_lang('users/password_wrong'); $errors['password']=qa_lang('users/password_wrong');
}
} else { } else {
if (strtolower(qa_db_calc_passcheck($inpassword, $userinfo['passsalt'])) == strtolower($userinfo['passcheck'])) { // login and redirect if (!$legacyPassOk) {
$errors['password']=qa_lang('users/password_wrong');
require_once QA_INCLUDE_DIR.'app/users.php'; }
qa_set_logged_in_user($inuserid, $userinfo['handle'], !empty($inremember)); }
$topath=qa_get('to'); if (!isset($errors['password'])) {
// login and redirect
require_once QA_INCLUDE_DIR.'app/users.php';
qa_set_logged_in_user($inuserid, $userinfo['handle'], !empty($inremember));
if (isset($topath)) $topath=qa_get('to');
qa_redirect_raw(qa_path_to_root().$topath); // path already provided as URL fragment
elseif ($passwordsent)
qa_redirect('account');
else
qa_redirect('');
} else if (isset($topath))
$errors['password']=qa_lang('users/password_wrong'); qa_redirect_raw(qa_path_to_root().$topath); // path already provided as URL fragment
elseif ($passwordsent)
qa_redirect('account');
else
qa_redirect('');
} }
} else } else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment