laravel5,\ Auth :: check(),返回true,但try()返回false

时间:2015-04-25 05:49:13

标签: php laravel

登录后,我想在控制器之前添加逻辑,所以我在中间件中写道。 但是,我发现我

dd(\Auth::check());  // it returns true;

但是

$eid = \Auth::user()->eid;  //can print the value
$password = \Auth::user()->password; //can print the value, too
dd(\Auth::validate(['eid'=>$eid,'password'=>$password]));  //it returns false  

整个代码:

public function handle($request, Closure $next)
{
    dd(\Auth::check());
    $eid = \Auth::user()->eid;
    $password = \Auth::user()->password;
    dd(\Auth::validate(['eid'=>$eid,'password'=>$password]));
    if ($this->auth->guest())
    { // not login
        if ($request->ajax())
        {
            return response('Unauthorized.', 401);
        }
        else
        {
            return redirect()->guest('auth/login');
        }
    }

    return $next($request);
}

1 个答案:

答案 0 :(得分:0)

Auth::user()->password是密码哈希,不能在validate()函数中使用。您只能在Auth::validate()

中使用实际的纯文本密码