承接 buckhamduffy/laravel-two-factor 相关项目开发

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

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

buckhamduffy/laravel-two-factor

最新稳定版本:v0.2.1

Composer 安装命令:

composer require buckhamduffy/laravel-two-factor

包简介

This is my package laravel-two-factor

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

An opinionated two factor authentication package for Laravel.

Installation

You can install the package via composer:

composer require buckhamduffy/laravel-two-factor

You can publish and run the migrations with:

php artisan vendor:publish --tag="two-factor-migrations" php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="two-factor-config"

This is the contents of the published config file:

return [ ];

Optionally, you can publish the views using

php artisan vendor:publish --tag="two-factor-views"

Add the trait and interface to the user model

 use BuckhamDuffy\LaravelTwoFactor\Traits\HasTwoFactor; use BuckhamDuffy\LaravelTwoFactor\Interfaces\HasTwoFactorInterface; class User extends Model implements HasTwoFactorInterface { use HasTwoFactor; }

Add the middleware to your Kernel.php

 protected $middlewareAliases = [ // ... '2fa' => \BuckhamDuffy\LaravelTwoFactor\Http\Middleware\TwoFactorMiddleware::class, ];
 Route::middleware('2fa')->group(function(){ // Your routes here });

SMS (Not Implemented Yet)

When a code is requested via SMS, an event will be dispatched that you can listen for to send the SMS. You can listen for the TwoFactorCodeRequested event and send the SMS using your preferred SMS provider.

 use \BuckhamDuffy\LaravelTwoFactor\Events\TwoFactorCodeRequested; class EventProvider extends ServiceProvider { protected $listen = [ // ... TwoFactorCodeRequested::class => [ \App\Listeners\SendTwoFactorCode::class, ], ]; }
 namespace App\Listeners; use BuckhamDuffy\LaravelTwoFactor\Events\TwoFactorCodeRequested; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; class SendTwoFactorCode implements ShouldQueue { use InteractsWithQueue; public function handle(TwoFactorCodeRequested $event): void { $user = $event->getUser(); $user->sendTwoFactorSms($event->getCode()); } }

CustomThrottlesLogins

This is a custom login throttler, that throttles based on the user's email address. This is to prevent brute force attacks on the login page.

First 5 attempts are allowed, then throttled for 5 minutes. The 8th attempt will be locked out for 15 minutes. Any subsequent attempts will be locked out for 1 hour.

Attempts are reset after successful login, or 24 hours after the last attempt.

use Illuminate\Foundation\Auth\AuthenticatesUsers; use BuckhamDuffy\LaravelTwoFactor\Traits\CustomThrottlesLogins; class LoginController extends Controller { use AuthenticatesUsers; use CustomThrottlesLogins { CustomThrottlesLogins::hasTooManyLoginAttempts insteadof AuthenticatesUsers; CustomThrottlesLogins::incrementLoginAttempts insteadof AuthenticatesUsers; CustomThrottlesLogins::clearLoginAttempts insteadof AuthenticatesUsers; CustomThrottlesLogins::sendLockoutResponse insteadof AuthenticatesUsers; } }

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 54.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固