PHPackages                             brians84/two-factor-auth-laravel - 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. brians84/two-factor-auth-laravel

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

brians84/two-factor-auth-laravel
================================

A package to handle 2FA authentication

028PHP

Since Jun 22Pushed 2y agoCompare

[ Source](https://github.com/brians84/two-factor-auth-laravel)[ Packagist](https://packagist.org/packages/brians84/two-factor-auth-laravel)[ RSS](/packages/brians84-two-factor-auth-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

2FA Auth for Laravel
====================

[](#2fa-auth-for-laravel)

A simple 2FA that uses Google Authenticator.

About The Project
-----------------

[](#about-the-project)

This project uses the following three packages:

- [pragmarx/google2fa-qrcode](https://packagist.org/packages/pragmarx/google2fa-qrcode)
- [pragmarx/google2fa-laravel](https://packagist.org/packages/pragmarx/google2fa-laravel)
- [bacon/bacon-qr-code](https://packagist.org/packages/bacon/bacon-qr-code)

You can obviously install those three packages and do it yourself, but this is a quick and easy implementation.

In short, this package requests users to validate their credentials with Google Authenticator right after they logged in.

- If the user never registered 2FA, it displays the setup page to do it.

[![screenshot-1](https://raw.githubusercontent.com/maurohmartinez/two-factor-auth-laravel/main/src/storage/sample/screenshot-setup.jpg)](https://raw.githubusercontent.com/maurohmartinez/two-factor-auth-laravel/main/src/storage/sample/screenshot-setup.jpg)

- If the user already did it, it displays the validation form.

[![screenshot-2](https://raw.githubusercontent.com/maurohmartinez/two-factor-auth-laravel/main/src/storage/sample/screenshot-validate.jpg)](https://raw.githubusercontent.com/maurohmartinez/two-factor-auth-laravel/main/src/storage/sample/screenshot-validate.jpg)

Also, if you have a "remember" input in your login form, we pick up on that and add a cookie after successful validation. So the next time the user visits the site, we don't ask again for 2FA validation. Once the user logs out, we removed the cookie.

### Installation

[](#installation)

1. Use composer to require this project

    ```
       composer require maurohmartinez/two-factor-auth-laravel
    ```
2. Run migrations

    ```
       php artisan migrate
    ```
3. Publish config, views, and public files and customize them as (and if) you need

    ```
       php artisan vendor:publish --provider="MHMartinez\TwoFactorAuth\app\Providers\TwoFactorAuthServiceProvider"
    ```
4. \[optional\] Adjust middleware group name

    This package automatically applies a middleware to route "admin", but you can adjust that by updating the config file:

    ```
    'middleware_route' => 'admin'
    ```

    You can also manually add the middleware `MHMartinez\TwoFactorAuth\app\Http\Middleware\TwoFactorAuthMiddleware` where you need it.
5. \[optional\] If you only want to ask certain users to validate 2FA, your `User` model should implement interface `MHMartinez\TwoFactorAuth\app\Interfaces\TwoFactorAuthInterface`. That will require you to add a new method `shouldValidateWithTwoFactorAuth` which should return a boolean indicating whether the middleware should skip that given user.

    Sample of your `User` Model Class:

    ```
    use MHMartinez\TwoFactorAuth\app\Interfaces\TwoFactorAuthInterface;

    class User extends Authenticate implements TwoFactorAuthInterface
    ```

    Sample of method `shouldValidateWithTwoFactorAuth()`:

    ```
    public function shouldValidateWithTwoFactorAuth(): bool
     {
         // do your logic here

         return true; // or false :)
     }
    ```
6. \[optional\] Disable this package in local environments by adding `TWO_FACTOR_AUTH_ENABLED=false` in your `.env`
7. \[optional\] Set in days when the one-time-password expires in the config file. FYI, 0 means it never expires `'2fa_expires' => 0,`

Contact
-------

[](#contact)

Project Link:

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 Bus Factor1

Top contributor holds 96.9% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1eeac313d02341b6128b55db918ac523cd490e9bc2f8c568185e321999ad6727?d=identicon)[brians84](/maintainers/brians84)

---

Top Contributors

[![maurohmartinez](https://avatars.githubusercontent.com/u/33960976?v=4)](https://github.com/maurohmartinez "maurohmartinez (62 commits)")[![brians84](https://avatars.githubusercontent.com/u/4737617?v=4)](https://github.com/brians84 "brians84 (2 commits)")

### Embed Badge

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

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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