首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel双因素身份验证-设置

Laravel双因素身份验证-设置
EN

Stack Overflow用户
提问于 2016-05-13 14:29:07
回答 3查看 3.7K关注 0票数 0

我已经通过下面的链接实现了双因素身份验证。

代码语言:javascript
复制
https://github.com/antonioribeiro/google2fa

它对我来说很好。我的问题是在google2fa中,有一行。

代码语言:javascript
复制
To use the two factor authentication, your user will have to install a Google Authenticator compatible app. 

如何使每个用户安装此应用程序,然后只有你会得到谷歌认证器2因素认证码。

有没有可能。以及如何在laravel中通过OTP实现双因素认证。即。OTP通过短信发送。请解释一下怎么做?

提前谢谢。

EN

回答 3

Stack Overflow用户

发布于 2017-03-25 04:18:58

安装

1. Composer安装

bash $ composer require thecodework/two-factor-authentication

2.添加服务提供商

在需要包之后,将TwoFactorAuthenticationServiceProvider::class添加到app.php配置文件中的providors数组中

php [ 'providers' => [ //... Thecodework\TwoFactorAuthentication\TwoFactorAuthenticationServiceProvider::class ] ]

3.运行迁移

现在运行迁移bash $ php artisan migrate,它将使用默认的用户模型,并添加两列is_2fa_enabledsecret_key

4.在AuthenticatesUserWith2FA 中添加特征

现在已经放置了配置文件。最后要做的是在Http/Controllers/Auth/LoginController.php文件中添加AuthenticatesUsersWith2FA特征,这有助于阻止用户在每次登录后在verify-2fa页面输入TOTP令牌。

最终的代码片段将如下所示。php use AuthenticatesUsers, AuthenticatesUsersWith2FA { AuthenticatesUsersWith2FA::authenticated insteadof AuthenticatesUsers; }注意:不要忘记在头文件中包含use语句use Thecodework\TwoFactorAuthentication\AuthenticatesUsersWith2FA

5.发布ConfigFile

最后,发布配置文件$ php artisan vendor:publish --provider="Thecodework\TwoFactorAuthentication\TwoFactorAuthenticationServiceProvider" --tag=config发布配置文件后,您可以导航到应用程序的配置目录,查找2fa-config.php文件并根据需要更改配置。

6.为用户设置2FA

·启用2FA

现在登录到应用程序并访问/setup-2fa/路由,它将显示一个条形码,可以使用Google Authenticator或Authy移动应用程序进行扫描,如上所述。扫描该代码,然后单击Enable Two Factor Authentication。

·禁用2FA

要禁用双因素身份验证,请访问/setup-2fa路由,现在将显示禁用双因素身份验证按钮。单击可为您的帐户禁用2FA。

7.测试2FA

现在测试2FA,执行注销并重新登录,它将要求您输入令牌,该令牌可以从验证器移动应用程序中获得。输入令牌即可登录。

票数 1
EN

Stack Overflow用户

发布于 2016-07-07 22:52:22

我已经为laravel创建了双因素身份验证,它也允许您通过SMS发送双因素身份验证令牌。只需访问以下link即可获得安装说明和示例。

我还创建了一个默认实现双因素身份验证的demo application

票数 0
EN

Stack Overflow用户

发布于 2019-05-12 03:42:41

如果您不想为此使用任何外部包,那么简单的步骤就是在用户的电子邮件中发送一个OTP。设置大纲将是-

创建mailable

  • Creating DB migrations

  • Setting up
  1. routes

添加两因素形式控制器和路由

有关同一主题的完整文章请参阅此处- https://bootsity.com/laravel/implementing-two-factor-authentication-in-laravel-applications

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37202703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档