|
|
|
|
@ -237,11 +237,15 @@ if (!empty($_SESSION['_user']['user_id']) && !($login || $logout)) { |
|
|
|
|
WHERE username = '".Database::escape_string($login)."'"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
$catpchaValidated = true; |
|
|
|
|
$captchaValidated = true; |
|
|
|
|
$allowCaptcha = isset($_configuration['allow_captcha']) ? $_configuration['allow_captcha'] : false; |
|
|
|
|
|
|
|
|
|
if (Database::num_rows($result) > 0) { |
|
|
|
|
$uData = Database::fetch_array($result); |
|
|
|
|
|
|
|
|
|
if ($allowCaptcha) { |
|
|
|
|
|
|
|
|
|
// Checking captcha |
|
|
|
|
if (isset($_POST['captcha'])) { |
|
|
|
|
// Check captcha |
|
|
|
|
$captchaText = $_POST['captcha']; |
|
|
|
|
@ -250,9 +254,9 @@ if (!empty($_SESSION['_user']['user_id']) && !($login || $logout)) { |
|
|
|
|
if ($obj) { |
|
|
|
|
$obj->getPhrase(); |
|
|
|
|
if ($obj->getPhrase() != $captchaText) { |
|
|
|
|
$catpchaValidated = false; |
|
|
|
|
$captchaValidated = false; |
|
|
|
|
} else { |
|
|
|
|
$catpchaValidated = true; |
|
|
|
|
$captchaValidated = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (isset($_SESSION['captcha_question'])) { |
|
|
|
|
@ -261,14 +265,35 @@ if (!empty($_SESSION['_user']['user_id']) && !($login || $logout)) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($catpchaValidated == false) { |
|
|
|
|
// Redirect to login page |
|
|
|
|
if ($captchaValidated == false) { |
|
|
|
|
$loginFailed = true; |
|
|
|
|
Session::erase('_uid'); |
|
|
|
|
Session::write('loginFailed', '1'); |
|
|
|
|
|
|
|
|
|
header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=wrong_captcha'); |
|
|
|
|
exit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check if account is blocked by captcha user extra field see function api_block_account_captcha() |
|
|
|
|
$blockedUntilDate = api_get_user_blocked_by_captcha($login); |
|
|
|
|
|
|
|
|
|
if (isset($blockedUntilDate) && !empty($blockedUntilDate)) { |
|
|
|
|
if (time() > api_strtotime($blockedUntilDate, 'UTC')) { |
|
|
|
|
api_clean_account_captcha($login); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
$loginFailed = true; |
|
|
|
|
Session::erase('_uid'); |
|
|
|
|
Session::write('loginFailed', '1'); |
|
|
|
|
|
|
|
|
|
header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=blocked_by_captcha'); |
|
|
|
|
exit; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE || $uData['auth_source'] == CAS_AUTH_SOURCE) { |
|
|
|
|
//The authentification of this user is managed by Chamilo itself |
|
|
|
|
$password = api_get_encrypted_password(trim(stripslashes($password))); |
|
|
|
|
@ -377,6 +402,24 @@ if (!empty($_SESSION['_user']['user_id']) && !($login || $logout)) { |
|
|
|
|
$loginFailed = true; |
|
|
|
|
Session::erase('_uid'); |
|
|
|
|
Session::write('loginFailed', '1'); |
|
|
|
|
|
|
|
|
|
if ($allowCaptcha) { |
|
|
|
|
|
|
|
|
|
if (isset($_SESSION['loginFailedCount'])) { |
|
|
|
|
$_SESSION['loginFailedCount']++; |
|
|
|
|
} else { |
|
|
|
|
$_SESSION['loginFailedCount'] = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$numberMistakesToBlockAccount = isset($_configuration['captcha_number_mistakes_to_block_account']) ? $_configuration['captcha_number_mistakes_to_block_account'] : 10; |
|
|
|
|
|
|
|
|
|
if (isset($_SESSION['loginFailedCount'])) { |
|
|
|
|
if ($_SESSION['loginFailedCount'] >= $numberMistakesToBlockAccount) { |
|
|
|
|
api_block_account_captcha($login); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=user_password_incorrect'); |
|
|
|
|
exit; |
|
|
|
|
} |
|
|
|
|
@ -619,7 +662,11 @@ if (isset($uidReset) && $uidReset) { // session data refresh requested |
|
|
|
|
|
|
|
|
|
if (isset($_user['user_id']) && $_user['user_id'] && ! api_is_anonymous()) { |
|
|
|
|
// a uid is given (log in succeeded) |
|
|
|
|
|
|
|
|
|
$_SESSION['loginFailed'] = false; |
|
|
|
|
unset($_SESSION['loginFailedCount']); |
|
|
|
|
unset($_SESSION['loginToBlock']); |
|
|
|
|
|
|
|
|
|
$user_table = Database::get_main_table(TABLE_MAIN_USER); |
|
|
|
|
$admin_table = Database::get_main_table(TABLE_MAIN_ADMIN); |
|
|
|
|
$track_e_login = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); |
|
|
|
|
|