title: How to authenticate user using phone number and OTP instead of password in Laravel API?
body: <p>I'm building an API for a mobile app where login is achieved through OTP sen via SMS to mobile phone devices.
  The user can login after he enters his phone number and an OTP code sent to his device.</p>
  <p>What am I trying to do?
  I'm trying to use otp code to authenticate users without passwords.</p>
  <p>How to disable passwords in laravel ?
  What is the best approach?
  Or if there's a way to use otp field instead of password for authentication.</p>
  <pre><code>  public function generateOtp(Request $request)
      {
          $identifier = $request-&gt;phone;
  
          $otp = new Otp();
          $code = $otp-&gt;generate($identifier, 6, 15);
   User::create([
             'phone'=&gt;$request-&gt;phone,
             'otp'=&gt;$code
          ]);
  
          //Todo::Send OTP number to sms
          return response()-&gt;json(['otp' =&gt; $code]);
      }
  
      public function login(Request $request)
  
      {
          $validator = Validator::make($request-&gt;all(), [
              'phone' =&gt; 'required',
              'otp' =&gt; 'required|min:6',
          ]);
  
          if ($validator-&gt;fails()) {
              return response()-&gt;json(['success' =&gt; false, 'data' =&gt; $validator-&gt;errors()], 400);
          }
  
          $otp = new Otp();
          $otp = $otp-&gt;validate($request-&gt;phone, $request-&gt;otp);
  
          if ($otp-&gt;status == true) {
  
              $credentials = [
                  'phone' =&gt; $request-&gt;phone,
              ];
  
              if (auth()-&gt;attempt($credentials)) {
  
                  $user = new UserResource(User::find($user-&gt;id));
  
                  $this-&gt;revokeTokens($user-&gt;id);
  
                  $token = $user-&gt;createToken('AccessToken')-&gt;accessToken;
  
                  $user-&gt;token = $token;
  
                  unset($user-&gt;code, $user-&gt;id, $user-&gt;created_at, $user-&gt;updated_at);
  
                  return response()-&gt;json(['success' =&gt; true, 'code' =&gt; 1500, 'user' =&gt; $user, 'token' =&gt; $token]);
  
              } else {
                  return ResponseHelper::notSuccessful(1502, 'login credentials are wrong');
              }
          }
  
          if ($otp-&gt;status == false) {
              return response()-&gt;json(['code'=&gt;2, 'message'=&gt;'OTP Expired. Generate New Code']);
          }
  
      }
  </code></pre>