如何允许用户使用手机号码和OTP登录我们的Laravel应用程序
答案 0 :(得分:1)
我通过以下方法实现了它, 在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和密码登录,当我找到合适的解决方案时,我将更新答案。
答案 1 :(得分:0)
不要使用任何包装。我想你会因为使用它而感到困惑。请参阅此(https://laravelcode.com/post/laravel-55-login-with-only-mobile-number-using-laravel-custom-auth)教程并使用移动设备进行基于自定义的登录并同时修改OTP。