在 Laravel 中使用手机号码和 OTP 进行用户身份验证

Kar*_*hik 3 laravel laravel-5 laravel-5.5

如何允许用户使用手机号码和 OTP 登录我们的 Laravel 应用程序

Roh*_*man 9

我通过以下方法实现了它,在 Laravel 5.7 和 Passport:

文件路径: /app/Http/Controllers/AuthController.php

编辑:

$credentials = request(['mobile_no', 'password', 'email', 'otp']);
Run Code Online (Sandbox Code Playgroud)

文件路径: /vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php

编辑:

public function validateCredentials(UserContract $user, array $credentials)
{
    if (isset($credentials['password'])) {
      $plain = $credentials['password'];
      return $this->hasher->check($plain, $user->getAuthPassword());
    }else{
      $otp = $credentials['otp'];
      if ($otp==$user->getAuthOtp()) {
        return true;
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

文件路径: /vendor/laravel/framework/src/Illuminate/Auth/Authenticatable.php

添加:

public function getAuthOtp()
    {
        return $this->otp;
    }
Run Code Online (Sandbox Code Playgroud)

注意:使用此用户还可以使用 OTP 和密码登录,当我找到合适的解决方案时,我会更新我的答案。