<commit_before><?php
/**
 * @file include/security.php
 */
use Friendica\App;
use Friendica\Core\Addon;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Group;

/**
 * @brief Calculate the hash that is needed for the "Friendica" cookie
 *
 * @param array $user Record from "user" table
 *
 * @return string Hashed data
 */
function cookie_hash($user)
{
	return(hash("sha256", Config::get("system", "site_prvkey") .
			$user["prvkey"] .
			$user["password"]));
}

/**
 * @brief Set the "Friendica" cookie
 *
 * @param int $time
 * @param array $user Record from "user" table
 */
function new_cookie($time, $user = [])
{
	if ($time != 0) {
		$time = $time + time();
	}

	if ($user) {
		$value = json_encode(["uid" => $user["uid"],
			"hash" => cookie_hash($user),
			"ip" => $_SERVER['REMOTE_ADDR']]);
	} else {
		$value = "";
	}

	setcookie("Friendica", $value, $time, "/", "", (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL), true);
}

/**
 * @brief Sets the provided user's authenticated session
 *
 * @todo Should be moved to Friendica\Core\Session once it's created
 *
 * @param type $user_record
 * @param type $login_initial
 * @param type $interactive
 * @param type $login_refresh
 */
function authenticate_success($user_record, $login_initial = false, $interactive = false, $login_refresh = false)
{
	$a = get_app();

	$_SESSION['uid'] = $user_record['uid'];
	$_SESSION['theme'] = $user_record['theme'];
	$_SESSION['mobile-theme'] = PConfig::get($user_record['uid'], 'system', 'mobile_theme');
	$_SESSION['authenticated'] = 1;
	$_SESSION['page_flags'] = $user_record['page-flags'];
	$_SESSION['my_url'] = System::baseUrl() . '/profile/' . $user_record['nickname'];
	$_SESSION['my_address'] = $user_record['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
	$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];

	$a->user = $user_record;

	if ($interactive) {
		if ($a->user['login_date'] <= NULL_DATE) {
			$_SESSION['return_url'] = 'profile_photo/new';
			$a->module = 'profile_photo';
			info(t("Welcome ") . $a->user['username'] . EOL);
			info(t('Please upload a profile photo.') . EOL);
		} else {
			info(t("Welcome back ") . $a->user['username'] . EOL);
		}
	}

	$member_since = strtotime($a->user['register_date']);
	if (time() < ($member_since + ( 60 * 60 * 24 * 14))) {
		$_SESSION['new_member'] = true;
	} else {
		$_SESSION['new_member'] = false;
	}
	if (strlen($a->user['timezone'])) {
		date_default_timezone_set($a->user['timezone']);
		$a->timezone = $a->user['timezone'];<commit_msg>Security t()<commit_after><?php
/**
 * @file include/security.php
 */
use Friendica\App;
use Friendica\Core\Addon;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Group;

/**
 * @brief Calculate the hash that is needed for the "Friendica" cookie
 *
 * @param array $user Record from "user" table
 *
 * @return string Hashed data
 */
function cookie_hash($user)
{
	return(hash("sha256", Config::get("system", "site_prvkey") .
			$user["prvkey"] .
			$user["password"]));
}

/**
 * @brief Set the "Friendica" cookie
 *
 * @param int $time
 * @param array $user Record from "user" table
 */
function new_cookie($time, $user = [])
{
	if ($time != 0) {
		$time = $time + time();
	}

	if ($user) {
		$value = json_encode(["uid" => $user["uid"],
			"hash" => cookie_hash($user),
			"ip" => $_SERVER['REMOTE_ADDR']]);
	} else {
		$value = "";
	}

	setcookie("Friendica", $value, $time, "/", "", (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL), true);
}

/**
 * @brief Sets the provided user's authenticated session
 *
 * @todo Should be moved to Friendica\Core\Session once it's created
 *
 * @param type $user_record
 * @param type $login_initial
 * @param type $interactive
 * @param type $login_refresh
 */
function authenticate_success($user_record, $login_initial = false, $interactive = false, $login_refresh = false)
{
	$a = get_app();

	$_SESSION['uid'] = $user_record['uid'];
	$_SESSION['theme'] = $user_record['theme'];
	$_SESSION['mobile-theme'] = PConfig::get($user_record['uid'], 'system', 'mobile_theme');
	$_SESSION['authenticated'] = 1;
	$_SESSION['page_flags'] = $user_record['page-flags'];
	$_SESSION['my_url'] = System::baseUrl() . '/profile/' . $user_record['nickname'];
	$_SESSION['my_address'] = $user_record['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
	$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];

	$a->user = $user_record;

	if ($interactive) {
		if ($a->user['login_date'] <= NULL_DATE) {
			$_SESSION['return_url'] = 'profile_photo/new';
			$a->module = 'profile_photo';
			info(L10n::t("Welcome ") . $a->user['username'] . EOL);
			info(L10n::t('Please upload a profile photo.') . EOL);
		} else {
			info(L10n::t("Welcome back ") . $a->user['username'] . EOL);
		}
	}

	$member_since = strtotime($a->user['register_date']);
	if (time() < ($member_since + ( 60 * 60 * 24 * 14))) {
		$_SESSION['new_member'] = true;
	} else {
		$_SESSION['new_member'] = false;
	}
	if (strlen($a->user['timezone'])) {
		date_default_timezone_set($a->user['timezone']);
		$a->timezone = $a->user['timezone'];
{'fraction_non_alphanumeric': 0.20959548447789275, 'fraction_numerical': 0.007149576669802446, 'mean_word_length': 4.8034934497816595, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '5680811', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1878, 'n_words': 390}