//Set staff object. //1) is the user Logged in for real && is staff. if (!$thisstaff->getId() || !$thisstaff->isValid()) { if (isset($_SESSION['_staff']['auth']['msg'])) { $msg = $_SESSION['_staff']['auth']['msg']; unset($_SESSION['_staff']['auth']['msg']); } elseif (isset($_SESSION['_staff']['userID']) && !$thisstaff->isValid()) { $msg = 'Session timed out due to inactivity'; } else { $msg = 'Authentication Required'; } staffLoginPage($msg); exit; } //2) if not super admin..check system status and group status if (!$thisstaff->isAdmin()) { //Check for disabled staff or group! if (!$thisstaff->isactive() || !$thisstaff->isGroupActive()) { staffLoginPage('Access Denied. Contact Admin'); exit; } //Staff are not allowed to login in offline mode!! if (!$ost->isSystemOnline() || $ost->isUpgradePending()) { staffLoginPage('System Offline'); exit; } } //Keep the session activity alive $thisstaff->refreshSession(); /******* CSRF Protectin *************/ // Enforce CSRF protection for POSTS
function authenticate($username, $password) { if (($user = new StaffSession($username)) && $user->getId() && $user->check_passwd($password)) { //update last login && password reset stuff. $sql = 'UPDATE ' . STAFF_TABLE . ' SET lastlogin=NOW() '; if ($user->isPasswdResetDue() && !$user->isAdmin()) { $sql .= ',change_passwd=1'; } $sql .= ' WHERE staff_id=' . db_input($user->getId()); db_query($sql); return $user; } }
function login($username, $passwd, &$errors, $strike = true) { global $ost, $cfg; if ($_SESSION['_staff']['laststrike']) { if (time() - $_SESSION['_staff']['laststrike'] < $cfg->getStaffLoginTimeout()) { $errors['err'] = 'You\'ve reached maximum failed login attempts allowed.'; } else { //Timeout is over. //Reset the counter for next round of attempts after the timeout. $_SESSION['_staff']['laststrike'] = null; $_SESSION['_staff']['strikes'] = 0; } } if (!$errors && ($user = new StaffSession($username)) && $user->getId() && $user->check_passwd($passwd)) { //update last login && password reset stuff. $sql = 'UPDATE ' . STAFF_TABLE . ' SET lastlogin=NOW() '; if ($user->isPasswdResetDue() && !$user->isAdmin()) { $sql .= ',change_passwd=1'; } $sql .= ' WHERE staff_id=' . db_input($user->getId()); db_query($sql); //Now set session crap and lets roll baby! $_SESSION['_staff'] = array(); //clear. $_SESSION['_staff']['userID'] = $username; $user->refreshSession(); //set the hash. $_SESSION['TZ_OFFSET'] = $user->getTZoffset(); $_SESSION['TZ_DST'] = $user->observeDaylight(); $ost->logDebug('Staff login', sprintf("%s logged in [%s]", $user->getUserName(), $_SERVER['REMOTE_ADDR'])); //Debug. $sid = session_id(); //Current ID session_regenerate_id(TRUE); //Destroy old session ID - needed for PHP version < 5.1.0 TODO: remove when we move to php 5.3 as min. requirement. if (($session = $ost->getSession()) && is_object($session) && $sid) { $session->destroy($sid); } session_write_close(); return $user; } //If we get to this point we know the login failed. $_SESSION['_staff']['strikes'] += 1; if (!$errors && $_SESSION['_staff']['strikes'] > $cfg->getStaffMaxLogins()) { $errors['err'] = 'Forgot your login info? Contact Admin.'; $_SESSION['_staff']['laststrike'] = time(); $alert = 'Excessive login attempts by a staff member?' . "\n" . 'Username: '******'username'] . "\n" . 'IP: ' . $_SERVER['REMOTE_ADDR'] . "\n" . 'TIME: ' . date('M j, Y, g:i a T') . "\n\n" . 'Attempts #' . $_SESSION['_staff']['strikes'] . "\n" . 'Timeout: ' . $cfg->getStaffLoginTimeout() / 60 . " minutes \n\n"; $ost->logWarning('Excessive login attempts (' . $_POST['username'] . ')', $alert, $cfg->alertONLoginError()); } elseif ($_SESSION['_staff']['strikes'] % 2 == 0) { //Log every other failed login attempt as a warning. $alert = 'Username: '******'username'] . "\n" . 'IP: ' . $_SERVER['REMOTE_ADDR'] . "\n" . 'TIME: ' . date('M j, Y, g:i a T') . "\n\n" . 'Attempts #' . $_SESSION['_staff']['strikes']; $ost->logWarning('Failed staff login attempt (' . $_POST['username'] . ')', $alert, false); } return false; }