在 Laravel 中使用手机号码和 OTP 进行用户身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48219708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
User Authentication with Mobile Number and OTP in Laravel
提问by Karthik
How to allow user, to login our Laravel application using Mobile Number and OTP
如何允许用户使用手机号码和 OTP 登录我们的 Laravel 应用程序
回答by Rohit Dhiman
I had implemented it through following approach, On Laravel 5.7 and Passport:
我通过以下方法实现了它,在 Laravel 5.7 和 Passport:
File Path:/app/Http/Controllers/AuthController.php
文件路径:/app/Http/Controllers/AuthController.php
Edit:
编辑:
$credentials = request(['mobile_no', 'password', 'email', 'otp']);
File Path:/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php
文件路径:/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php
Edit:
编辑:
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;
}
}
}
File Path:/vendor/laravel/framework/src/Illuminate/Auth/Authenticatable.php
文件路径:/vendor/laravel/framework/src/Illuminate/Auth/Authenticatable.php
Add:
添加:
public function getAuthOtp()
{
return $this->otp;
}
Note:Using this user is also able to login with OTP and password, I will update my answer when I found an appropriate solution for that.
注意:使用此用户还可以使用 OTP 和密码登录,当我找到合适的解决方案时,我会更新我的答案。
回答by abhishek jain
Don't use any package. I think you will be confused by using this. See this ( https://laravelcode.com/post/laravel-55-login-with-only-mobile-number-using-laravel-custom-auth) tutorial and make custom based login with mobile and varify OTP as well.
不要使用任何包。我想你会因为使用它而感到困惑。请参阅此(https://laravelcode.com/post/laravel-55-login-with-only-mobile-number-using-laravel-custom-auth)教程,并使用移动设备进行基于自定义的登录并更改 OTP。