<commit_before><?php
    
    /**
     * Manage tokens (definition, check, destroy)
     * 
     * @package Core
    **/
    class Token {
        
        const LIFETIME = 300; // 5 minutes
        
        
        /**
         * Generate a token
         * @param string    $name
        **/
        public static function generate($name) {
            $token = uniqid(sha1(time()));
			$_SESSION['tokens'][$name] = array(
                'key' => $token,
                'time' => time()
            );
			return $token;
        }
        
        
        /**
         * Check token validity
         * @param string    $name
         * @param string    $key
         * @param integer   $lifetime
        **/
        public static function authorized($name, $key, $lifetime = Token::LIFETIME) {
            $token = self::_get($name);
            if(!$token) return false;
            
            if(empty($lifetime))
                $lifetime = Token::LIFETIME;
            
            $elapsed = time() - $token['time'];
            
            return ($key == $token['key'] && $elapsed <= $lifetime) ? true : false;
        }
        
        
        /**
         * Destroy token
         * @param string    $name
        **/
        public static function destroy($name) {
            unset($_SESSION['tokens'][$name]);
        }
        
        
        /**
         * Get token's value
         * @param string    $name
        **/
        private static function _get($name) {
            $tokens = Session::has('tokens') ? Session::get('tokens') : array();
                        
            if(!empty($tokens[$name]))
                return $tokens[$name];
            else
                return false;
        }
        
        
    }

?><commit_msg>Tokens class now use Session class<commit_after><?php
    
    /**
     * Manage tokens (definition, check, destroy)
     * 
     * @package Core
    **/
    class Token {
        
        const LIFETIME = 300; // 5 minutes
        
        
        /**
         * Generate a token
         * @param string    $name
        **/
        public static function generate($name) {
			Session::set("tokens.$name", array(
                'key' => $token = uniqid(sha1(time())),
                'time' => time()
            ));
			return $token;
        }
        
        
        /**
         * Check token validity
         * @param string    $name
         * @param string    $key
         * @param integer   $lifetime
        **/
        public static function authorized($name, $key, $lifetime = Token::LIFETIME) {
            $token = self::_get($name);
            if(!$token) return false;
            
            if(empty($lifetime))
                $lifetime = Token::LIFETIME;
            
            $elapsed = time() - $token['time'];
            
            return ($key == $token['key'] && $elapsed <= $lifetime) ? true : false;
        }
        
        
        /**
         * Destroy token
         * @param string    $name
        **/
        public static function destroy($name) {
            Session::delete("tokens.$name");
        }
        
        
        /**
         * Get token's value
         * @param string    $name
        **/
        private static function _get($name) {
            $tokens = Session::has('tokens') ? Session::get('tokens') : array();
                        
            if(!empty($tokens[$name]))
                return $tokens[$name];
            else
                return false;
        }
        
        
    }

?>
{'fraction_non_alphanumeric': 0.13077790304396844, 'fraction_numerical': 0.002818489289740699, 'mean_word_length': 1.1457073760580412, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2703517', 'n_tokens_mistral': 958, 'n_tokens_neox': 929, 'n_words': 208}