<commit_before><?php

/**
 * Encryption
 * @package framework
 * @subpackage crypt
 */

/**
 * Manage request keys for modules
 */
class Hm_Request_Key {

    /* site key */
    private static $site_hash = false;

    /**
     * Load the request key
     * @param object $session session interface
     * @param object $request request object
     * @param bool $just_logged_in true if the session was created on this request
     * @return void
     */
    public static function load($session, $request, $just_logged_in) {
        if ($session->is_active() && !$just_logged_in) {
            $user = $session->get('username', false);
        }
        else {
            $user = '';
        }
        self::$site_hash = $session->build_fingerprint($request->server, $user.SITE_ID);
    }

    /**
     * Return the request key
     * @return string request key
     */
    public static function generate() {<commit_msg>improve CSRF/Request key token with random bytes<commit_after><?php

/**
 * Encryption
 * @package framework
 * @subpackage crypt
 */

/**
 * Manage request keys for modules
 */
class Hm_Request_Key {

    /* site key */
    private static $site_hash = false;

    /**
     * Load the request key
     * @param object $session session interface
     * @param object $request request object
     * @param bool $just_logged_in true if the session was created on this request
     * @return void
     */
    public static function load($session, $request, $just_logged_in) {
        $user = '';
        $key = '';
        if ($session->is_active()) {
            if (!$just_logged_in) {
                $user = $session->get('username', '');
                $key = $session->get('request_key', '');
            }
            else {
                $session->set('request_key', Hm_Crypt::unique_id());
            }
        }
        self::$site_hash = $session->build_fingerprint($request->server, $key.$user.SITE_ID);
    }

    /**
     * Return the request key
     * @return string request key
     */
    public static function generate() {
{'fraction_non_alphanumeric': 0.12790697674418605, 'fraction_numerical': 0.0, 'mean_word_length': 2.2265625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4767086', 'n_tokens_mistral': 596, 'n_tokens_neox': 586, 'n_words': 163}