How to login without password using Auth::attempt in Laravel 5.0?
According to the documentation:
the user will be retrieved by the value of the email column. If the user is found, the hashed password stored in the database will be compared with the hashed password value passed to the method via the array.
So, password will must be checked in this method and hence it's a required parameter.
You can login like following:
$user = User::where('USER_NAME', '=', $_GET['UserName'])->first();
if (empty($user)) {
abort(404);
}
if(Auth::loginUsingId($user->id)){
return redirect('Home');
}
hendraspt
Updated on July 09, 2022Comments
-
hendraspt almost 2 years
I am using Laravel 5.0. I want do a login only with username (no password) because I am using Single Sign On to access to my Laravel project, so if user success login in Single Sign On, it will check to my database if the username of the user who login has registered or not.
I have looking for this all day but I still have found the clue.
I have got an error:Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given
if I am using the code below in my LoginController:
$user = User::where('USER_NAME', '=', $_GET['UserName'])->first(); if(Auth::login($user)->USER_ID == $_GET['UserName']){ return redirect('Home'); }
And if I am using the code below in my LoginController:
if(Auth::attempt(['USER_ID' => $_GET['UserName']])){ return redirect('Home'); }
I have got an error:
Undefined index: password
-
hendraspt over 7 yearsI have tried that and I have got an error
NotFoundHttpException in Application.php line 901: