繁体   English   中英

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

[英]laravel5 ,\Auth::check(),return true,but attempt() return false

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

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);
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM