在laravel 5.4中,是否可以在不登录的情况下对用户进行身份验证?从laravel doc开始,我能找到的最接近的是:
Auth::once($credentials)
但是这仍然记录了用户对该一个请求的转发。我只需要知道是否存在使用该电子邮件和密码的用户。
答案 0 :(得分:4)
您可以将Auth::attempt
函数与第三个参数false
一起用于登录
$email=$request->email;
$password=$request->password;
if(Auth::attempt(['email'=>$email, 'password'=>$password],false,false))
{
echo "found":
}else {
echo "not found";
}
选中此https://laravel.com/api/5.1/Illuminate/Auth/Guard.html#method_attempt
或使用Auth::validate
https://laravel.com/api/5.1/Illuminate/Auth/Guard.html#method_validate
答案 1 :(得分:1)
如果您只需检查用户是否存在给定凭据,请执行以下操作:
//get the user by email
$user = User::where('email',$email)->first();
if($user !== null){
// if user is found, check if password match against given text
$isRightPassword = Hash::verify($password,$user->password);
}
上述代码不会对用户进行身份验证。