prevents a token to be re-used
is usually called directly by ::is_valid()

@return void
774353
public function mark_as_used() {
	$mysql = bootstrap::get_library('mysql');
	
	$sql   = "UPDATE `login_tokens` SET `used` = 1, `last_used_at` = %d WHERE `id` = %d;";
	$binds = [time(), $this->data['id']];
	$mysql::query($sql, $binds);
}
965703
public function isTokenValid($token) {
        $record = List_Unsubscribe_Token::where('token', $token)->first();

        if (!$record) {
            return false;
        }
        return true;
    }
1326142
public function clear()
    {
        $count = $this->loadModel('Muffin/Tokenize.Tokens')->deleteAllExpiredOrUsed();
        $this->out(__n('One token deleted', '{0} tokens deleted', $count, $count));
    }
1025587
public function endForm(): void
    {
        $useCsrf = (isset($this->formOptions['use_csrf'])) ?
            filter_var($this->formOptions['use_csrf'], FILTER_VALIDATE_BOOLEAN)
            : true;

        $tokenField = ($useCsrf) ? HtmlTag::createElement('input')
            ->set('id', 'csrf_token')
            ->set('name', 'csrf_token')
            ->set('type', 'hidden')
            ->set('value', $this->generateCsrfToken())
            : '';

        echo $tokenField . '</form>';
    }
673073
def _token_valid(self):
        
        if not self._cache_token:
            return False
        now = time.time()
        if now - self._token.acquired_time > self._token_timeout:
            logger.debug('token needs to be reset')
            return False
        return True
600472
public function safeUp()
    {
        Craft::log('Altering craft_oauth_tokens accessToken, secret and refreshToken columns to text...', LogLevel::Info, true);

        $this->alterColumn('oauth_tokens', 'accessToken', array(ColumnType::Text));
        $this->alterColumn('oauth_tokens', 'secret', array(ColumnType::Text));
        $this->alterColumn('oauth_tokens', 'refreshToken', array(ColumnType::Text));

        Craft::log('Done altering craft_oauth_tokens accessToken, secret and refreshToken columns to text...', LogLevel::Info, true);

        return true;
    }
81193
private function validateToken($token = null)
    {

        if (is_null($token)) {
            return false;
        }
        $decrypted = Crypt::decrypt($token);
        $args      = unserialize($decrypted);
        if (!isset($args['protection_string']) or $args['protection_string'] !== config('antares/search::protection_string')) {
            return false;
        }
        if (!isset($args['app_key']) or $args['app_key'] !== env('APP_KEY')) {
            return false;
        }
        return true;
    }
1276944
public function getRefreshToken()
    {
        if (is_string($this->refresh_token) && $this->isValidToken() ){

            $this->refreshToken = $this->token_type . ' ' . $this->refresh_token;

            return $this->refreshToken;
        }

        return false;
    }
360991
public function checkToken()
    {
        // Skip CSRF request by config
        if( \Config::get( 'tiga.skip_csrf_protect',false ) )
            return;

        if ($this->session->get('tiga_csrf_token', false) == false) {
            throw new \Exception('Invalid csrf token');
        }

        $input = $this->input('_tiga_token');

        if ($this->isXmlHttpRequest()) {
            $input = $this->headers->get('X-CSRF-Tiga-Token');
        }

        if ($this->session->get('tiga_csrf_token') != $input) {
            throw new \Exception('Invalid csrf token');
        }
    }
1337103
protected function isTokenValid() {
    if ($this->isTokenValid) {
      // already validated
      return true;
    }
    $request = ObjectFactory::getInstance('request');
    $token = $request->hasHeader(self::TOKEN_HEADER) ? $request->getHeader(self::TOKEN_HEADER) :
        $request->getValue(self::TOKEN_HEADER, null);
    $this->isTokenValid = $token != null && $token == $_COOKIE[$this->tokenName];
    return $this->isTokenValid;
  }
598264
def revoke_tokens(self):
        

        self.is_active = False
        self.save()

        self.refresh_token.revoke_tokens()
638460
protected function processToken(): void
    {
        $this->checkLinesBeforeFirstUse($this->uses[0]);
        $this->checkLinesAfterLastUse($this->uses[count($this->uses) - 1]);

        if (count($this->uses) > 1) {
            $this->checkLinesBetweenUses();
        }
    }
366454
public function validateCsrf()
    {
        $tokenService = $this->getServiceLocator()->get(TokenService::SERVICE_ID);

        $tokenName = $tokenService->getTokenName();
        $token = $this->getRequestParameter($tokenName);

        if ( $tokenService->checkToken($token) ) {
            $tokenService->revokeToken($token);
            $newToken = $tokenService->createToken();
            $this->setCookie($tokenName, $newToken, null, '/');
            return true;
        }

        \common_Logger::w('Csrf validation failed');
        throw new \common_exception_Unauthorized();
    }
276344
protected function initializeTokenCharacters()
    {
        $allowed = 'abcdefghijklmnopqrstuvwxyz';
        $allowed .= strtoupper($allowed);
        $allowed .= '0123456789';
        //$allowed .= '!§$%&?';
        $this->tokenChars = str_split($allowed);
        shuffle($this->tokenChars);
    }
519109
public function revokeToken($token)
    {
        $this->oauth->token = $token;
        $this->oauth->calltokenHandler();

        if ( ! $this->hasErrors()) {
            return $this->model->deleteToken(['key' => $token]);
        }

        return false;
    }
1000632
public function validateToken()
	{
		if ($this->token !== $this->getToken())
		{
			// Using 'public' as the session ID allows for shareable URLs
			// not tied to a specific user session. Usage would be for
			// files that do not need access control.
			$this->session_id = 'public';
		}
		return ($this->token === $this->getToken());
	}
1110773
public function reset() {
		$this->index = 0;
		$this->tokens = array();
		$this->newTokens = array();
		$this->tokenNumber = 0;
		$this->lineNumber = 1;
	}