Laravel双因素身份验证 - 设置

时间:2016-05-13 06:29:07

标签: laravel authentication laravel-5.2 two-factor-authentication

我已通过以下链接实施了双因素身份验证。

https://github.com/antonioribeiro/google2fa

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

To use the two factor authentication, your user will have to install a Google Authenticator compatible app. 

如何让每个用户安装此应用,然后只有您将获得谷歌身份验证器2因素身份验证代码。

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

提前致谢。

3 个答案:

答案 0 :(得分:1)

安装

<强> 1。作曲家安装

bash $ composer require thecodework/two-factor-authentication

<强> 2。添加服务提供商

要求包将TwoFactorAuthenticationServiceProvider::class添加到app.php confi文件中的提供者数组

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

第3。运行迁移

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

<强> 4。在LoginController中添加AuthenticatesUserWith2FA特征

现在放置了配置文件。最后要做的是在AuthenticatesUsersWith2FA文件中添加Http/Controllers/Auth/LoginController.php特征,这有助于在每次登录后阻止用户在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 发布配置文件后,您可以导航到应用程序的config目录并查找2fa-config.php文件并根据需要更改配置。

<强> 6。为用户设置2FA

•启用2FA

现在登录该应用程序并访问/setup-2fa/路径,该路径将显示条形码,可以使用Google身份验证器或Authy移动应用程序扫描,如上所述。 扫描该代码,然后单击启用双因素身份验证

•停用2FA

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

<强> 7。测试2FA

现在要测试2FA,执行注销并重新登录,它会要求您输入可以从身份验证器移动应用程序获取的令牌。输入令牌即表示您已登录。

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

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

  1. 添加两因素形式
  2. 创建可邮寄邮件
  3. 创建数据库迁移
  4. 设置控制器和路由

同一篇文章的全文-https://bootsity.com/laravel/implementing-two-factor-authentication-in-laravel-applications

相关问题