Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5:在VerifyCsrfToken外部验证令牌_Php_Security_Laravel_Controller_Laravel 5 - Fatal编程技术网

Php Laravel 5:在VerifyCsrfToken外部验证令牌

Php Laravel 5:在VerifyCsrfToken外部验证令牌,php,security,laravel,controller,laravel-5,Php,Security,Laravel,Controller,Laravel 5,我需要验证Laravel 5令牌,在VerifyCsrfToken类之外 是否有方法从控制器调用VerifyCsrfToken->handle 或者使用任何不同的方式验证它们?返回(会话(“U令牌”)==$variableYouNeedToCheck) 类似于,但具有定时安全比较: use Symfony\Component\Security\Core\Util\StringUtils; // ... return StringUtils::equals(session('_token'), $

我需要验证Laravel 5令牌,在
VerifyCsrfToken
类之外

是否有方法从
控制器调用
VerifyCsrfToken->handle

或者使用任何不同的方式验证它们?

返回(会话(“U令牌”)==$variableYouNeedToCheck)

类似于,但具有定时安全比较:

use Symfony\Component\Security\Core\Util\StringUtils;
// ...
return StringUtils::equals(session('_token'), $variableYouNeedToCheck);

不要使用
==
来比较字符串,请使用与PHP5.6相当的东西

请参阅下面的代码以获得一个简单的工作代码

use Illuminate\Support\Facades\Request;
class MyController extends Controller {

      public function getIndex(Request $request)
         if(hash_equals(request->get('myCSRFTokenFromMyFormOrAjax'), Session::token())){
             // token not matches please 
             //redirect or stop the application here 
         }
      }
 } 
出于安全原因,我使用的哈希有时可能是相同的,用于不同的值

如果您不理解上面的代码,请阅读


还要注意的是,使用它最好创建一个中间件,以获得对代码的控制,并且不要在任何地方重复代码的和平

$request
不是Controllersanswer updeted中定义的变量。顺便说一句,当你需要这张支票时,你能解释一下吗?-1不要使用
=
要比较哈希,请至少使用
==但出于安全目的,您肯定需要
StringUtils::equals()
谢谢您的添加。我已经读到了关于它的内容,现在我得到了安全问题。