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

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

maurohmartinez/two-factor-auth-laravel
======================================

A package to handle 2FA authentication

2.2.6(7mo ago)31.6k↓50%1MITPHPPHP ^8.1

Since May 7Pushed 7mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (63)Used By (0)

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

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/9d54b44763ba7b8c3c024774cdcab26025e364e6f8e91dc1bd47f7de1d1240dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6175726f686d617274696e657a2f74776f2d666163746f722d617574682d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maurohmartinez/two-factor-auth-laravel)[![Total Downloads](https://camo.githubusercontent.com/dc0ede123fc45bba5a075cedc5a4730ff4ccad4344564e6bec189a86e3e840fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6175726f686d617274696e657a2f74776f2d666163746f722d617574682d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maurohmartinez/two-factor-auth-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

46

—

FairBetter than 93% of packages

Maintenance65

Regular maintenance activity

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~21 days

Recently: every ~63 days

Total

62

Last Release

215d ago

Major Versions

v1.0.51 → v2.0.02023-10-17

PHP version history (2 changes)v1.0.3PHP ^8.0

2.2PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/21192abc454e8b809201f9150490b1b6f694cfdf3e6494d04fb915b9fb1e697d?d=identicon)[maurohmartinez](/maintainers/maurohmartinez)

---

Top Contributors

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

---

Tags

2fa2fa-securityauthenticationlaravellaravel-packagemiddlewarelaravelTwo Factor Authenticationbackpackgoogle authentication for laravel

### Embed Badge

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

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

###  Alternatives

[pragmarx/google2fa-laravel

A One Time Password Authentication package, compatible with Google Authenticator.

1.0k15.5M63](/packages/pragmarx-google2fa-laravel)[stephenjude/filament-two-factor-authentication

Filament Two Factor Authentication: Google 2FA + Passkey Authentication

81158.7k4](/packages/stephenjude-filament-two-factor-authentication)[maurohmartinez/impersonate-users-backpack-laravel

A simple package that adds the impersonate operation for admins

118.8k](/packages/maurohmartinez-impersonate-users-backpack-laravel)

PHPackages © 2026

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