Search code examples
laravellaravel-authentication

Laravel authenticate via phone number


I don't want to use Laravel's built in authentication because it has the traditional username/password approach. The way my system is authenticated is basically

  1. You login with your Client ID and Last Name and they are tested against the database
  2. Once they are correct, the user details (including phone number) are stored in a session variable and it sends you an OTP to your phone number. If the OTP matches, you are then taken to the home screen.

Being new, I just can't get my head around manually authenticating the user. In the documentation, it says to use Auth::attempt() but this compares the data against the database. The code I have is just comparing the random generated OTP.


Solution

  • This line:

    Auth::login($user)
    

    Will log the user in.