username; } $result = elgg_authenticate($username, $password); // Open log openlog("elgg({$_SERVER['HTTP_HOST']})", LOG_PID, LOG_AUTH); $ip = $_SERVER['REMOTE_ADDR']; if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $proxies = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); // We are behind a proxy $ip = trim($proxies[0]); } if ($result !== true) { // Log authentication error, in a format almost identical to the SSH rule (for compatibility) syslog(LOG_NOTICE,"Authentication failure for $username from $ip"); register_error($result); forward(REFERER); } // We got here, so login was successful syslog(LOG_INFO,"Accepted password for $username from $ip"); closelog(); $user = get_user_by_username($username); if (!$user) { register_error(elgg_echo('login:baduser')); forward(REFERER); } try { login($user, $persistent); // re-register at least the core language file for users with language other than site default register_translations(dirname(dirname(__FILE__)) . "/languages/"); } catch (LoginException $e) { register_error($e->getMessage()); forward(REFERER); } // elgg_echo() caches the language and does not provide a way to change the language. // @todo we need to use the config object to store this so that the current language // can be changed. Refs #4171 if ($user->language) { $message = elgg_echo('loginok', array(), $user->language); } else { $message = elgg_echo('loginok'); } system_message($message); forward($forward_url);