user1985273
user1985273

Reputation: 1967

Laravel - authenticating user without logging in

In laravel 5.4 is it possible to authenticate user without logging him in? From laravel doc the closest thing i could find was:

Auth::once($credentials)

But this still logged the user in for the duriation of that one request. All i need is to just know if user with that email and password exists.

Upvotes: 3

Views: 3027

Answers (2)

Niklesh Raut
Niklesh Raut

Reputation: 34914

You can use Auth::attempt function with third parameter as false which is for login

 $email=$request->email;
 $password=$request->password;
 if(Auth::attempt(['email'=>$email, 'password'=>$password],false,false))
   {
        echo "found":
    }else {
        echo "not found";
   }

Check this https://laravel.com/api/5.1/Illuminate/Auth/Guard.html#method_attempt

Or use Auth::validate

https://laravel.com/api/5.1/Illuminate/Auth/Guard.html#method_validate

Upvotes: 6

Luka Isailovic
Luka Isailovic

Reputation: 126

If all you need is to check if User exist with given credentials do it like this:

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

The above code will not authenticate User.

Upvotes: 1

Related Questions