/** * This function is called when a user initially tries to login. * * @param string $username * @param string $password * @param array $PARAMS * @return boolean true if the user successfully logs in or false otherwise. */ public function login($username, $password, $PARAMS = array()) { //kbrill bug #13225 $_SESSION['loginAttempts'] = isset($_SESSION['loginAttempts']) ? $_SESSION['loginAttempts'] + 1 : 1; unset($GLOBALS['login_error']); if ($this->loggedIn) { return $this->loginSuccess; } LogicHook::initialize()->call_custom_logic('Users', 'before_login'); $this->loginSuccess = $this->authController->loginAuthenticate($username, $password, false, $PARAMS); $this->loggedIn = true; if ($this->loginSuccess) { //Ensure the user is authorized checkAuthUserStatus(); //loginLicense(); if (!empty($GLOBALS['login_error'])) { unset($_SESSION['authenticated_user_id']); $GLOBALS['log']->fatal('FAILED LOGIN: potential hack attempt:' . $GLOBALS['login_error']); $this->loginSuccess = false; return false; } //call business logic hook if (isset($GLOBALS['current_user'])) { $GLOBALS['current_user']->call_custom_logic('after_login'); } // Check for running Admin Wizard $config = new Administration(); $config->retrieveSettings(); $postSilentInstallAdminWizardCompleted = $GLOBALS['current_user']->getPreference('postSilentInstallAdminWizardCompleted'); if (is_admin($GLOBALS['current_user']) && empty($config->settings['system_adminwizard']) && $_REQUEST['action'] != 'AdminWizard' || $postSilentInstallAdminWizardCompleted !== NULL && !$postSilentInstallAdminWizardCompleted) { $GLOBALS['module'] = 'Configurator'; $GLOBALS['action'] = 'AdminWizard'; ob_clean(); header("Location: index.php?module=Configurator&action=AdminWizard"); sugar_cleanup(true); } $ut = $GLOBALS['current_user']->getPreference('ut'); $checkTimeZone = true; if (is_array($PARAMS) && !empty($PARAMS) && isset($PARAMS['passwordEncrypted'])) { $checkTimeZone = false; } // if if (empty($ut) && $checkTimeZone && $_REQUEST['action'] != 'SetTimezone' && $_REQUEST['action'] != 'SaveTimezone') { $GLOBALS['module'] = 'Users'; $GLOBALS['action'] = 'Wizard'; ob_clean(); header("Location: index.php?module=Users&action=Wizard"); sugar_cleanup(true); } } else { //kbrill bug #13225 LogicHook::initialize(); $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed'); $GLOBALS['log']->fatal('FAILED LOGIN:attempts[' . $_SESSION['loginAttempts'] . '] - ' . $username); } // if password has expired, set a session variable return $this->loginSuccess; }
public function loginAuthenticate() { $user = $this->box->getCurrentUser(); if (empty($user)) { SugarApplication::redirect($this->box->loginUrl()); } if (parent::loginAuthenticate($user['email'], '', false)) { // delete session when done // $this->box->deleteSession(); return true; } return false; }
/** * Authenticates a user based on the username and password * returns true if the user was authenticated false otherwise * it also will load the user into current user if he was authenticated * * @param string $username * @param string $password * @return boolean */ function loginAuthenticate($username, $password, $fallback = false) { global $mod_strings; session_unregister('login_error'); if ($this->userAuthenticate->loadUserOnLogin($username, $password, $fallback)) { return $this->postLoginAuthenticate(); } if (strtolower(get_class($this)) != 'sugarauthenticate') { $sa = new SugarAuthenticate(); $error = !empty($_SESSION['login_error']) ? $_SESSION['login_error'] : ''; if ($sa->loginAuthenticate($username, $password, true)) { return true; } $_SESSION['login_error'] = $error; } $_SESSION['login_user_name'] = $username; $_SESSION['login_password'] = $password; if (empty($_SESSION['login_error'])) { $_SESSION['login_error'] = $mod_strings['ERR_INVALID_PASSWORD']; } return false; }
/** * Authenticates a user based on the username and password * returns true if the user was authenticated false otherwise * it also will load the user into current user if he was authenticated * * @param string $username * @param string $password * @return boolean */ function loginAuthenticate($username, $password, $fallback = false, $PARAMS = array()) { global $mod_strings; unset($_SESSION['login_error']); $usr = new user(); $usr_id = $usr->retrieve_user_id($username); $usr->retrieve($usr_id); $_SESSION['login_error'] = ''; $_SESSION['waiting_error'] = ''; $_SESSION['hasExpiredPassword'] = '******'; if ($this->userAuthenticate->loadUserOnLogin($username, $password, $fallback, $PARAMS)) { require_once 'modules/Users/password_utils.php'; if (hasPasswordExpired($username)) { $_SESSION['hasExpiredPassword'] = '******'; } // now that user is authenticated, reset loginfailed if ($usr->getPreference('loginfailed') != '' && $usr->getPreference('loginfailed') != 0) { $usr->setPreference('loginfailed', '0'); $usr->savePreferencesToDB(); } return $this->postLoginAuthenticate(); } else { if (!empty($usr_id) && $res['lockoutexpiration'] > 0) { if (($logout = $usr->getPreference('loginfailed')) == '') { $usr->setPreference('loginfailed', '1'); } else { $usr->setPreference('loginfailed', $logout + 1); } $usr->savePreferencesToDB(); } } if (strtolower(get_class($this)) != 'sugarauthenticate') { $sa = new SugarAuthenticate(); $error = !empty($_SESSION['login_error']) ? $_SESSION['login_error'] : ''; if ($sa->loginAuthenticate($username, $password, true, $PARAMS)) { return true; } $_SESSION['login_error'] = $error; } $_SESSION['login_user_name'] = $username; $_SESSION['login_password'] = $password; if (empty($_SESSION['login_error'])) { $_SESSION['login_error'] = translate('ERR_INVALID_PASSWORD', 'Users'); } return false; }
/** * Authenticates a user based on the username and password * returns true if the user was authenticated false otherwise * it also will load the user into current user if he was authenticated * * @param string $username * @param string $password * @return boolean */ function loginAuthenticate($username, $password, $fallback = false, $PARAMS = array()) { global $app_strings; unset($_SESSION['login_error']); $res = $GLOBALS['sugar_config']['passwordsetting']; $usr = BeanFactory::getBean('Users'); $usr->retrieve_by_string_fields(array('user_name' => $username)); $_SESSION['login_error'] = ''; $_SESSION['waiting_error'] = ''; $_SESSION['hasExpiredPassword'] = '******'; $usr->reloadPreferences(); // if there is too many login attempts if (!empty($usr->id) && $res['lockoutexpiration'] > 0 && $usr->getPreference('loginfailed') >= $res['lockoutexpirationlogin'] && !$usr->portal_only) { // if there is a lockout time set if ($res['lockoutexpiration'] == '2') { // lockout date is now if not set if (($logout_time = $usr->getPreference('logout_time')) == '') { $usr->setPreference('logout_time', TimeDate::getInstance()->nowDb()); $logout_time = $usr->getPreference('logout_time'); } // Bug # 45922 - calculating the expiretime properly $stim = strtotime($logout_time); $mins = $res['lockoutexpirationtime'] * $res['lockoutexpirationtype']; $expiretime = TimeDate::getInstance()->fromDb($logout_time)->modify("+{$mins} minutes")->asDb(); // Test if the user is still locked out and return a error message if (TimeDate::getInstance()->nowDb() < $expiretime) { $usr->setPreference('lockout', '1'); $_SESSION['login_error'] = $app_strings['LBL_LOGIN_ATTEMPTS_OVERRUN'] . ' '; $_SESSION['login_error'] .= $app_strings['LBL_LOGIN_LOGIN_TIME_ALLOWED'] . ' '; $lol = strtotime($expiretime) - strtotime(TimeDate::getInstance()->nowDb()); switch (true) { case floor($lol / 86400) != 0: $_SESSION['login_error'] .= floor($lol / 86400) . $app_strings['LBL_LOGIN_LOGIN_TIME_DAYS']; break; case floor($lol / 3600) != 0: $_SESSION['login_error'] .= floor($lol / 3600) . $app_strings['LBL_LOGIN_LOGIN_TIME_HOURS']; break; case floor($lol / 60) != 0: $_SESSION['login_error'] .= floor($lol / 60) . $app_strings['LBL_LOGIN_LOGIN_TIME_MINUTES']; break; case floor($lol) != 0: $_SESSION['login_error'] .= floor($lol) . $app_strings['LBL_LOGIN_LOGIN_TIME_SECONDS']; break; } $usr->savePreferencesToDB(); return false; } else { $usr->setPreference('lockout', ''); $usr->setPreference('loginfailed', '0'); $usr->setPreference('logout_time', ''); $usr->savePreferencesToDB(); } } else { $usr->setPreference('lockout', '1'); $_SESSION['login_error'] = $app_strings['LBL_LOGIN_ATTEMPTS_OVERRUN']; $_SESSION['waiting_error'] = $app_strings['LBL_LOGIN_ADMIN_CALL']; $usr->savePreferencesToDB(); return false; } } if ($this->userAuthenticate->loadUserOnLogin($username, $password, $fallback, $PARAMS)) { require_once 'modules/Users/password_utils.php'; if (hasPasswordExpired($username, true)) { $_SESSION['hasExpiredPassword'] = '******'; } // now that user is authenticated, reset loginfailed if ($usr->getPreference('loginfailed') != '' && $usr->getPreference('loginfailed') != 0) { $usr->setPreference('loginfailed', '0'); $usr->savePreferencesToDB(); } $this->updateUserLastLogin($usr); return $this->postLoginAuthenticate(); } else { if (!empty($usr->id) && isset($res['lockoutexpiration']) && $res['lockoutexpiration'] > 0) { if (($logout = $usr->getPreference('loginfailed')) == '') { $usr->setPreference('loginfailed', '1'); } else { $usr->setPreference('loginfailed', $logout + 1); } $usr->savePreferencesToDB(); } } if (strtolower(get_class($this)) != 'sugarauthenticate') { $sa = new SugarAuthenticate(); $error = !empty($_SESSION['login_error']) ? $_SESSION['login_error'] : ''; if ($sa->loginAuthenticate($username, $password, true, $PARAMS)) { return true; } $_SESSION['login_error'] = $error; } $_SESSION['login_user_name'] = $username; $_SESSION['login_password'] = $password; if (empty($_SESSION['login_error'])) { $_SESSION['login_error'] = translate('ERR_INVALID_PASSWORD', 'Users'); } return false; }
/** * Authenticates a user based on the username and password * returns true if the user was authenticated false otherwise * it also will load the user into current user if he was authenticated * * @param string $username * @param string $password * @return boolean */ function loginAuthenticate($username, $password, $fallback = false) { global $mod_strings; session_unregister('login_error'); $usr = new user(); $usr_id = $usr->retrieve_user_id($username); $usr->retrieve($usr_id); $_SESSION['login_error'] = ''; $_SESSION['waiting_error'] = ''; $_SESSION['hasExpiredPassword'] = '******'; if ($this->userAuthenticate->loadUserOnLogin($username, $password, $fallback)) { require_once 'modules/Users/password_utils.php'; if (hasPasswordExpired($username)) { $_SESSION['hasExpiredPassword'] = '******'; } return $this->postLoginAuthenticate(); } else { if (!empty($usr_id)) { if (($logout = $usr->getPreference('loginfailed')) == '') { $usr->setPreference('loginfailed', '1'); } else { $usr->setPreference('loginfailed', $logout + 1); } $usr->savePreferencesToDB(); } } if (strtolower(get_class($this)) != 'sugarauthenticate') { $sa = new SugarAuthenticate(); $error = !empty($_SESSION['login_error']) ? $_SESSION['login_error'] : ''; if ($sa->loginAuthenticate($username, $password, true)) { return true; } $_SESSION['login_error'] = $error; } $_SESSION['login_user_name'] = $username; $_SESSION['login_password'] = $password; if (empty($_SESSION['login_error'])) { $_SESSION['login_error'] = $mod_strings['ERR_INVALID_PASSWORD']; } return false; }