<commit_before><?php 
// get built-in php classes
$system_classes = get_declared_classes();
$system_classes[] = 'DB';

include '../lib/common.php';

$session_id1 = (!empty($_POST['session_id'])) ? preg_replace("/[^0-9]/","",$_POST['session_id']) : false;
$signature1 = (!empty($_POST['signature'])) ? hex2bin($_POST['signature']) : false;
$nonce1 = (!empty($_POST['nonce'])) ? preg_replace("/[^0-9]/","",$_POST['nonce']) : false;
$token1 = (!empty($_POST['token'])) ? preg_replace("/[^0-9]/","",$_POST['token']) : false;
$settings_change_id1 = (!empty($_POST['settings_change_id'])) ? $_REQUEST['settings_change_id'] : false;
$request_id1 = (!empty($_POST['request_id'])) ? $_REQUEST['request_id'] : false;
$api_key1 = (!empty($_POST['api_key'])) ? preg_replace("/[^0-9a-zA-Z]/","",$_POST['api_key']) : false;
$api_signature1 = (!empty($_POST['api_signature'])) ? preg_replace("/[^0-9a-zA-Z]/","",$_POST['api_signature']) : false;
$update_nonce = false;

$CFG->language = (!empty($_POST['lang']) && in_array(strtolower($_POST['lang']),array('en','es','ru','zh'))) ? strtolower($_POST['lang']) : false;
$CFG->client_ip = (!empty($_POST['ip'])) ? preg_replace("/[^0-9\.]/","",$_POST['ip']) : false;
$CFG->session_id = $session_id1;
$CFG->session_locked = false;
$CFG->session_active = false;
$CFG->session_api = false;
$CFG->token_verified = false;
$CFG->email_2fa_verified = false;

// commands is of form array('Class1'=>array('method1'=>array('arg1'=>blah,'arg2'=>bob)));
$commands = (!empty($_POST['commands'])) ? json_decode($_POST['commands'],true) : false;

// authenticate session
if ($session_id1) {
	$result = db_query_array('SELECT sessions.nonce AS nonce ,sessions.session_key AS session_key, sessions.awaiting AS awaiting, site_users.* FROM sessions LEFT JOIN site_users ON (sessions.user_id = site_users.id) WHERE sessions.session_id = '.$session_id1);
	if ($result && $result[0]['nonce'] >= ($nonce1 + 5) && $result[0]['nonce'] <= ($nonce1 - 5)) {
		$return['error'] = 'invalid-nonce';
	}
	elseif (!empty($result)) {
		if (!empty($_POST['commands']) && openssl_verify($_POST['commands'],$signature1,$result[0]['session_key'])) {
			User::setInfo($result[0]);
			$update_nonce = true;
			
			if (User::$info['locked'] == 'Y' || User::$info['deactivated'] == 'Y') {
				$return['error'] = 'account-locked-or-deactivated';
				$CFG->session_locked = true;
			}
			else {
				$CFG->session_active = true;
			}
			<commit_msg>Reduced number of nonce updates.<commit_after><?php 
// get built-in php classes
$system_classes = get_declared_classes();
$system_classes[] = 'DB';

include '../lib/common.php';

$session_id1 = (!empty($_POST['session_id'])) ? preg_replace("/[^0-9]/","",$_POST['session_id']) : false;
$signature1 = (!empty($_POST['signature'])) ? hex2bin($_POST['signature']) : false;
$nonce1 = (!empty($_POST['nonce'])) ? preg_replace("/[^0-9]/","",$_POST['nonce']) : false;
$token1 = (!empty($_POST['token'])) ? preg_replace("/[^0-9]/","",$_POST['token']) : false;
$settings_change_id1 = (!empty($_POST['settings_change_id'])) ? $_REQUEST['settings_change_id'] : false;
$request_id1 = (!empty($_POST['request_id'])) ? $_REQUEST['request_id'] : false;
$api_key1 = (!empty($_POST['api_key'])) ? preg_replace("/[^0-9a-zA-Z]/","",$_POST['api_key']) : false;
$api_signature1 = (!empty($_POST['api_signature'])) ? preg_replace("/[^0-9a-zA-Z]/","",$_POST['api_signature']) : false;
$update_nonce = false;

$CFG->language = (!empty($_POST['lang']) && in_array(strtolower($_POST['lang']),array('en','es','ru','zh'))) ? strtolower($_POST['lang']) : false;
$CFG->client_ip = (!empty($_POST['ip'])) ? preg_replace("/[^0-9\.]/","",$_POST['ip']) : false;
$CFG->session_id = $session_id1;
$CFG->session_locked = false;
$CFG->session_active = false;
$CFG->session_api = false;
$CFG->token_verified = false;
$CFG->email_2fa_verified = false;

// commands is of form array('Class1'=>array('method1'=>array('arg1'=>blah,'arg2'=>bob)));
$commands = (!empty($_POST['commands'])) ? json_decode($_POST['commands'],true) : false;

// authenticate session
if ($session_id1) {
	$result = db_query_array('SELECT sessions.nonce AS nonce ,sessions.session_key AS session_key, sessions.awaiting AS awaiting, site_users.* FROM sessions LEFT JOIN site_users ON (sessions.user_id = site_users.id) WHERE sessions.session_id = '.$session_id1);
	if ($result && ($nonce1 >= ($result[0]['nonce'] + 5) || $nonce1 <= ($result[0]['nonce'] - 5))) {
		$return['error'] = 'invalid-nonce';
	}
	elseif (!empty($result)) {
		if (!empty($_POST['commands']) && openssl_verify($_POST['commands'],$signature1,$result[0]['session_key'])) {
			User::setInfo($result[0]);
			$update_nonce = $_POST['update_nonce'];
			
			if (User::$info['locked'] == 'Y' || User::$info['deactivated'] == 'Y') {
				$return['error'] = 'account-locked-or-deactivated';
				$CFG->session_locked = true;
			}
			else {
				$CFG->session_active = true;
			}
			
{'fraction_non_alphanumeric': 0.2498471571224781, 'fraction_numerical': 0.015488078255553291, 'mean_word_length': 6.716981132075472, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5478895', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1703, 'n_words': 268}