【问题标题】:Laravel Two Factor Authentication - setupLaravel 两因素身份验证 - 设置
【发布时间】:2016-09-09 05:16:33
【问题描述】:

我通过以下链接实现了两因素身份验证。

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 实现两因素身份验证。 IE。 OTP 通过短信发送。请解释一下怎么做?

提前致谢。

【问题讨论】:

  • 要求他们这样做。我错过了什么吗?

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


【解决方案1】:

安装

1.作曲家安装

bash $ composer require thecodework/two-factor-authentication

2。添加服务提供商

要求包后将TwoFactorAuthenticationServiceProvider::class添加到app.phpconf文件中的providors数组中

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

3.运行迁移

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

4.在 LoginController 中添加 AuthenticatesUserWith2FA trait

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

最终的 sn-p 将如下所示。 php use AuthenticatesUsers, AuthenticatesUsersWith2FA { AuthenticatesUsersWith2FA::authenticated insteadof AuthenticatesUsers; } 注意:不要忘记在标题中包含使用语句use Thecodework\TwoFactorAuthentication\AuthenticatesUsersWith2FA

5.发布配置文件

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

6.为用户设置 2FA

• 启用 2FA

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

• 禁用 2FA

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

7.测试 2FA

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

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

      完整的文章在这里 - https://bootsity.com/laravel/implementing-two-factor-authentication-in-laravel-applications

      【讨论】:

        猜你喜欢
        • 2019-07-21
        • 2011-03-19
        • 2019-07-21
        • 1970-01-01
        • 1970-01-01
        • 2012-11-03
        • 2016-06-06
        • 2016-02-21
        • 1970-01-01
        相关资源
        最近更新 更多