承接 top20ofe/two-factor-authentication 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

top20ofe/two-factor-authentication

Composer 安装命令:

composer require top20ofe/two-factor-authentication

包简介

Two Factor Authentication (2FA) for Laravel

README 文档

README

1. Composer Install

$ composer require top20ofe/two-factor-authentication

Note - If your're using Laravel 5.5 or newer version then auto-discovery-pacakge would automatically update the providers and you could skip to Step 3

2. Add Service Provider

After requiring the package add TwoFactorAuthenticationServiceProvider::class into providors array in app.php confi file

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

3. Publish the ConfigFile

Publish config file

$ php artisan vendor:publish --provider="Top20ofe\TwoFactorAuthentication\TwoFactorAuthenticationServiceProvider" --tag=config

Once the config file is published you can navigate to config directory of your application and look for 2fa-config.php file and change configuration as you want.

4. Run Migrations

Now run the migration

$ php artisan migrate

It will use the default User model and adds two columns is_2fa_enabled and secret_key.

5. Add AuthenticatesUserWith2FA trait in the LoginController

Now the config file is placed. The last thing to do is addding AuthenticatesUsersWith2FA trait in the Http/Controllers/Auth/LoginController.php file which helps to stop user at verify-2fa page to enter TOTP token after each login.

The final snippet will look like this.

use AuthenticatesUsers, AuthenticatesUsersWith2FA {
    AuthenticatesUsersWith2FA::authenticated insteadof AuthenticatesUsers;
}

Note: Don't forget to include use statement use Top20ofe\TwoFactorAuthentication\AuthenticatesUsersWith2FA in the header.

6. Setup 2FA for user

• Enable 2FA

Now login to the application and visit /setup-2fa/ route, which will show a barcode which can be scanned either using Google Authenticator or Authy mobile application as described above. Scan that code and click Enable Two Factor Authentication.

• Disable 2FA

To disable Two Factor, visit /setup-2fa route, which will now show a Disable Two Factor Authentication button. Click to disable 2FA for your account.

7. Testing 2FA

Now to test 2FA, perform logout and log back in again, it will ask you to enter Token which can be obtain from the authenticator mobile application. Enter the token and you're logged in.

Additionally

If you want to publish views, and migration as well along with config file then run

$ php artisan vendor:publish --provider="Top20ofe\TwoFactorAuthentication\TwoFactorAuthenticationServiceProvider"

统计信息

  • 总下载量: 276
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固