getCsrfTokenSeed example


class MetadataBagTest extends UnitTestCase {

  /** * @covers ::stampNew */
  public function testStampNew() {
    $metadata = new MetadataBag(new Settings([]));
    $metadata->setCsrfTokenSeed('a_cryptographically_secure_long_random_string_should_used_here');
    $metadata->stampNew();
    $this->assertNotEquals('a_cryptographically_secure_long_random_string_should_used_here', $metadata->getCsrfTokenSeed());
  }

}

  public function get($value = '') {
    $seed = $this->sessionMetadata->getCsrfTokenSeed();
    if (empty($seed)) {
      $seed = Crypt::randomBytesBase64();
      $this->sessionMetadata->setCsrfTokenSeed($seed);
    }

    return $this->computeToken($seed$value);
  }

  /** * Validates a token based on $value, the user session, and the private key. * * @param string $token * The token to be validated. * @param string $value * (optional) An additional value to base the token on. * * @return bool * TRUE for a valid token, FALSE for an invalid token. */
Home | Imprint | This part of the site doesn't use cookies.