PHPackages                             buckhamduffy/laravel-two-factor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. buckhamduffy/laravel-two-factor

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

buckhamduffy/laravel-two-factor
===============================

This is my package laravel-two-factor

v0.2.1(7mo ago)163.5k↓30%[1 issues](https://github.com/buckhamduffy/laravel-two-factor/issues)[13 PRs](https://github.com/buckhamduffy/laravel-two-factor/pulls)MITPHPPHP ^8.2CI passing

Since Feb 29Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/buckhamduffy/laravel-two-factor)[ Packagist](https://packagist.org/packages/buckhamduffy/laravel-two-factor)[ Docs](https://github.com/buckhamduffy/laravel-two-factor)[ GitHub Sponsors](https://github.com/BuckhamDuffy)[ RSS](/packages/buckhamduffy-laravel-two-factor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (15)Versions (29)Used By (0)

Laravel Two Factor
==================

[](#laravel-two-factor)

[![Latest Version on Packagist](https://camo.githubusercontent.com/abd8f7f4b0ad16d60437b7543ebbee3b3f089a42c88dafbcc131161890fe6aa7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6275636b68616d64756666792f6c61726176656c2d74776f2d666163746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/buckhamduffy/laravel-two-factor)[![GitHub Tests Action Status](https://camo.githubusercontent.com/d486f383c6fc673e5a72909b07aee945f5eee943fa18343b350bce719539db8b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6275636b68616d64756666792f6c61726176656c2d74776f2d666163746f722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/buckhamduffy/laravel-two-factor/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/6065ec66ee6b5d05fbee19f8c480cb3bb960448d38f82f7ca203373d1fb6ac1e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6275636b68616d64756666792f6c61726176656c2d74776f2d666163746f722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/buckhamduffy/laravel-two-factor/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/0595d63ab088d26be127fd0337ff02f2e063d5f3590e9d0b374807fa44d6ace8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6275636b68616d64756666792f6c61726176656c2d74776f2d666163746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/buckhamduffy/laravel-two-factor)

An opinionated two factor authentication package for Laravel.

Installation
------------

[](#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)

[](#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

[](#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
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Aaron Florey](https://github.com/aaronflorey)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance59

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~48 days

Recently: every ~144 days

Total

13

Last Release

228d ago

PHP version history (2 changes)v0.0.1PHP ^8.1

v0.1.5PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/fdee3bef55bb13a185bf9c93506c503663bfda63628214782d56f2f8830c35e5?d=identicon)[Mochaka](/maintainers/Mochaka)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (349 commits)")[![mvdnbrk](https://avatars.githubusercontent.com/u/802681?v=4)](https://github.com/mvdnbrk "mvdnbrk (46 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (19 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (17 commits)")[![pforret](https://avatars.githubusercontent.com/u/474312?v=4)](https://github.com/pforret "pforret (16 commits)")[![aaronflorey](https://avatars.githubusercontent.com/u/948073?v=4)](https://github.com/aaronflorey "aaronflorey (14 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (14 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (13 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (10 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (7 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (7 commits)")[![crynobone](https://avatars.githubusercontent.com/u/172966?v=4)](https://github.com/crynobone "crynobone (7 commits)")[![irfanm96](https://avatars.githubusercontent.com/u/42065936?v=4)](https://github.com/irfanm96 "irfanm96 (5 commits)")[![thecaliskan](https://avatars.githubusercontent.com/u/13554944?v=4)](https://github.com/thecaliskan "thecaliskan (5 commits)")[![IGedeon](https://avatars.githubusercontent.com/u/694313?v=4)](https://github.com/IGedeon "IGedeon (4 commits)")[![yaroslawww](https://avatars.githubusercontent.com/u/23663794?v=4)](https://github.com/yaroslawww "yaroslawww (3 commits)")[![abenerd](https://avatars.githubusercontent.com/u/7523903?v=4)](https://github.com/abenerd "abenerd (3 commits)")[![jessarcher](https://avatars.githubusercontent.com/u/4977161?v=4)](https://github.com/jessarcher "jessarcher (3 commits)")[![koossaayy](https://avatars.githubusercontent.com/u/6431084?v=4)](https://github.com/koossaayy "koossaayy (3 commits)")

---

Tags

laravelbuckhamduffylaravel-two-factor

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/buckhamduffy-laravel-two-factor/health.svg)

```
[![Health](https://phpackages.com/badges/buckhamduffy-laravel-two-factor/health.svg)](https://phpackages.com/packages/buckhamduffy-laravel-two-factor)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[jeffgreco13/filament-breezy

A custom package for Filament with login flow, profile and teams support.

1.0k1.7M41](/packages/jeffgreco13-filament-breezy)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[spatie/laravel-login-link

Quickly login to your local environment

4381.2M1](/packages/spatie-laravel-login-link)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)[spatie/laravel-passkeys

Use passkeys in your Laravel app

444494.4k16](/packages/spatie-laravel-passkeys)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
