@bobbybouwmann
I want to build a login system without password.
I searched a lot and found out that if we replace validateCredentials method with true in EloquentUserProvider, we could do that.
But How can I do that without changing this file in vendor :(
Should I make my own AuthProvider for that?
here is the EloquentUserProvider class
<?php
namespace Illuminate\Auth;
use Illuminate\Support\Str;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
class EloquentUserProvider implements UserProvider
{
public function validateCredentials(UserContract $user, array $credentials)
{
//It works great if we Change this block of method to true
$plain = $credentials['password'];
return $this->hasher->check($plain, $user->getAuthPassword());
}
I'm afraid it's not working
because I'm making a rest API and I login users with token and phone_number.
Cause it's stateless, I don't use login and auth controller for that.
I use my own login method in UserController using these:
The validateCredentials method is not something you can simply override without doing a lot of black magic. So creating your own AuthProvider seems to be the right decision here.
Just curious! How are you going to build the login stuff without the password? Probably sending an email with some login token right? If that is the case you might not even need a new AuthProvider. Instead you need a controller that checks the login request with the generated token and that logs the user in right?
// Assuming the link in the email will be something like this
example.com/login?token=123y124ib1ku23bhj12b3h1212
// PasswordLessLoginController
public function login(Request $request)
{
$token = $request->get('token');
$loginRequest = LoginRequest::where('token', $token);
Auth::loginUsingId($loginRequest->user_id)
}
So this assumes that when your user requests for a login request you create a new LoginRequest in the database and send an email with the token. You can then use the token to verify the user and log it in right? No need for a new AuthProvider
Note: This is a really basic example. Just generating a token might not be enough for security. Also make sure to took at expiring these tokens and so on.
thank you all, here is my scenario :
Users put their number in the app, I send the verification code to their mobile phone.
then user put verification code in the app and I check that verification number with Database and then I log them in.
So I want to use Auth driver to log them in..
NOTE:: and by login, I mean work with Auth and know who requested