Created
July 21, 2011 10:09
-
-
Save loonies/1096905 to your computer and use it in GitHub Desktop.
Kohana CSRF validation rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
/** | |
* Extension of Kohana_Security class | |
* | |
* @package Misc | |
* @category Security | |
* @author Miodrag Tokić <mtokic@gmail.com> | |
* @copyright (c) 2011, Miodrag Tokić | |
*/ | |
class Security extends Kohana_Security { | |
/** | |
* Checks if CSRF token is valid | |
* | |
* This is a shortcut combination of Valid::not_empty and Security::check rules | |
* | |
* // Set CSRF validation rule | |
* Validation::factory($array)->rule('csrf', 'Security::csrf'); | |
* | |
* @uses Valid::not_empty | |
* @uses Security::check | |
* @param string CSRF token | |
* @return bool | |
*/ | |
public static function csrf($token) | |
{ | |
return Valid::not_empty($token) AND Security::check($token); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
return array( | |
'Security::csrf' => 'Form has expired.', | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment