Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.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.4中手动验证用户身份_Php_Laravel_Authentication_Laravel 5 - Fatal编程技术网

Php 如何在Laravel 5.4中手动验证用户身份

Php 如何在Laravel 5.4中手动验证用户身份,php,laravel,authentication,laravel-5,Php,Laravel,Authentication,Laravel 5,我正在尝试验证laravel 5.4中的用户,使用尝试()我可以验证用户,但我还想检查用户是否处于活动状态,并根据用户是否处于非活动状态显示自定义消息,然后显示不同的消息,如果用户名密码不同,则显示不同的消息 我的身份验证代码: public function checklogin(Request $request) { $password = bcrypt($request->password); $userData = User::where('

我正在尝试验证laravel 5.4中的用户,使用尝试()我可以验证用户,但我还想检查用户是否处于活动状态,并根据用户是否处于非活动状态显示自定义消息,然后显示不同的消息,如果用户名密码不同,则显示不同的消息

我的身份验证代码:

public function checklogin(Request $request)
    {
        $password = bcrypt($request->password);
        $userData = User::where('email',$request->email)->where('password',$password)->first();
        if($userData!=NULL)
        {
            $credentials=array('email' => $request->input('email'),'password' => $request->input('password'),'status' => 'active');

            if(Auth::guard('users')->attempt($credentials)) 
                return redirect()->intended('/dashboard');
             else
             {
                Mail::to($request->email)->send(new VerifyUser($userData));
                return redirect('/')->with('error','Your account is unverified - check your email for account verification link');
             }
        }
        else
            return redirect('/')->with('error','Invalid username or password');


    }
在这里,我首先要检查登录凭据是否正确,如果它们无效,那么它将直接显示错误消息“无效用户名或密码”,如果假设登录凭据正确,那么我尝试登录,如果用户处于非活动状态,那么我想显示消息“您需要验证您的帐户”,若用户处于活动状态,那个么它会将用户重定向到仪表板


但在我的情况下,即使我在db表中键入密码并与密码交叉检查,我也无法对用户进行身份验证。

请注意注释。这应该行得通

  public function checklogin(Request $request)
    {
      $password = bcrypt($request->password);
      $userData = User::where('email',$request->email)->where('password',$password);
      if($userData->get()->count() > 0) //Check if User exists
      {
        if($userData->where('status','inactive')->get()->count() > 0) // Check if User is inactive
        {
          Mail::to($request->email)->send(new VerifyUser($userData->get()->first()));
          return redirect('/')->with('error','Your account is unverified - check your email for account verification link');
        }

        $credentials=array('email' => $request->input('email'),'password' => $password); // passing hashed password

        if(Auth::guard('users')->attempt($credentials)) 
          return redirect()->intended('/dashboard');
      }
      else
        return redirect('/')->with('error','Invalid username or password');
    }

请注意评论。这应该行得通

  public function checklogin(Request $request)
    {
      $password = bcrypt($request->password);
      $userData = User::where('email',$request->email)->where('password',$password);
      if($userData->get()->count() > 0) //Check if User exists
      {
        if($userData->where('status','inactive')->get()->count() > 0) // Check if User is inactive
        {
          Mail::to($request->email)->send(new VerifyUser($userData->get()->first()));
          return redirect('/')->with('error','Your account is unverified - check your email for account verification link');
        }

        $credentials=array('email' => $request->input('email'),'password' => $password); // passing hashed password

        if(Auth::guard('users')->attempt($credentials)) 
          return redirect()->intended('/dashboard');
      }
      else
        return redirect('/')->with('error','Invalid username or password');
    }

但是,有很多方法可以做到这一点,因为您在评论中提到,您有兴趣让代码中的第4行正常工作

$userData = User::where('email',$request->email)->where('password',$password);
由于
bcrypt
生成的新哈希与数据库中的哈希密码不匹配,因此上面的行将不起作用

您可以这样做:

$userData = User::where('email',$request->email)->first();

if ($userData && Hash::check($request->password, $userData->password))
{
    // The passwords match...
}

但是,有很多方法可以做到这一点,因为您在评论中提到,您有兴趣让代码中的第4行正常工作

$userData = User::where('email',$request->email)->where('password',$password);
由于
bcrypt
生成的新哈希与数据库中的哈希密码不匹配,因此上面的行将不起作用

您可以这样做:

$userData = User::where('email',$request->email)->first();

if ($userData && Hash::check($request->password, $userData->password))
{
    // The passwords match...
}

可能重复,文档不是我想要的,我的查询使用的是bcrypt。我无法交叉验证表中存储的密码,有其他方法吗?您正在将
$request->input('password')
传递到
凭据
,这不是使用
bcrypt
散列的密码。您好,请检查第3行和第4行,我想要一个解决方案好的。在数据库中存储
Active
Inactive
的位置。。给我字段名..可能重复,文档不是我想要的,我的查询使用的是bcrypt。我无法交叉验证表中存储的密码,有其他方法吗?您正在将
$request->input('password')
传递到
凭据
,这不是使用
bcrypt
散列的密码。您好,请检查第3行和第4行,我想要一个解决方案好的。在数据库中存储
Active
Inactive
的位置。。给我字段名。。