如何允许用户使用手机号码和 OTP 登录我们的 Laravel 应用程序
最佳答案
我通过以下方法实现了它, 在 Laravel 5.7 和 Passport 上:
文件路径:/app/Http/Controllers/AuthController.php
编辑:
$credentials = request(['mobile_no', 'password', 'email', 'otp']);
文件路径:/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;
}
}
}
文件路径:/vendor/laravel/framework/src/Illuminate/Auth/Authenticatable.php
添加:
public function getAuthOtp()
{
return $this->otp;
}
注意:使用此用户还可以使用 OTP 和密码登录,当我找到合适的解决方案时,我会更新我的答案。
关于laravel - Laravel 中使用手机号码和 OTP 进行用户身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48219708/