key() public static method

Generates a single-use key to be embedded in a form or used with another non-idempotent request (a request that changes the state of the server or application), that will match against a client session token using the check() method.
See also: lithium\security\validation\RequestToken::check()
public static key ( array $options = [] ) : string
$options array An array of options to be passed to `RequestToken::get()`.
return string Returns a hashed key string for use with `RequestToken::check()`.
 /**
  * Tests extracting a key from a `Request` object and matching it against a token.
  */
 public function testTokenFromRequestObject()
 {
     $request = new Request(array('data' => array('security' => array('token' => RequestToken::key()))));
     $this->assertTrue(RequestToken::check($request));
 }
Example #2
0
File: CSRF.php Project: qujian/rwe
 /**
  * 生成token
  * @param array $config
  * @return string
  */
 public static function generate(array $config = array())
 {
     self::$_token = RequestToken::key(array('sessionKey' => self::$_session_key, 'salt' => null) + $config);
     return self::$_token;
 }