maurohmartinez/two-factor-auth-laravel
| Install | |
|---|---|
composer require maurohmartinez/two-factor-auth-laravel |
|
| Latest Version: | 2.2.6 |
| PHP: | ^8.1 |
| License: | MIT |
| Last Updated: | Oct 16, 2025 |
| Links: | GitHub · Packagist |
About The Project
This project uses the following three packages:
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.

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

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
-
Use composer to require this project
composer require maurohmartinez/two-factor-auth-laravel -
Run migrations
php artisan migrate -
Publish config, views, and public files and customize them as (and if) you need
php artisan vendor:publish --provider="MHMartinez\TwoFactorAuth\app\Providers\TwoFactorAuthServiceProvider" -
[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\TwoFactorAuthMiddlewarewhere you need it. -
[optional] If you only want to ask certain users to validate 2FA, your
Usermodel should implement interfaceMHMartinez\TwoFactorAuth\app\Interfaces\TwoFactorAuthInterface. That will require you to add a new methodshouldValidateWithTwoFactorAuthwhich should return a boolean indicating whether the middleware should skip that given user.Sample of your
UserModel Class:use MHMartinez\TwoFactorAuth\app\Interfaces\TwoFactorAuthInterface; class User extends Authenticate implements TwoFactorAuthInterfaceSample of method
shouldValidateWithTwoFactorAuth():public function shouldValidateWithTwoFactorAuth(): bool { // do your logic here return true; // or false :) } -
[optional] Disable this package in local environments by adding
TWO_FACTOR_AUTH_ENABLED=falsein your.env -
[optional] Set in days when the one-time-password expires in the config file. FYI, 0 means it never expires
'2fa_expires' => 0,
Contact
Project Link: https://github.com/maurohmartinez/two-factor-auth-laravel
Related Packages
Quickly build admin interfaces using Laravel, Bootstrap and JavaScript.
Users and permissions management interface for Laravel 5 using Backpack CRUD.
A One Time Password Authentication package, compatible with Google Authenticator...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 2.2.6 | ^8.1 | ^8.0.0| | MIT | |
| 2.2.5 | ^8.1 | ^8.0.0| | MIT | |
| 2.2.4 | ^8.1 | ^8.0.0| | MIT | |
| 2.2.3 | ^8.1 | ^8.0.0| | MIT | |
| 2.2.2 | ^8.1 | ^8.0.0| | MIT | |
| 2.2.1 | ^8.1 | ^8.0.0| | MIT | |
| 2.2 | ^8.1 | ^8.0.0| | MIT | |
| 2.1.3 | ^8.0 | ^8.0.0| | MIT | |
| 2.1.2 | ^8.0 | ^8.0.0| | MIT | |
| 2.1.1 | ^8.0 | ^8.0.0| | MIT | |
| 2.1.0 | ^8.0 | ^8.0.0| | MIT | |
| 2.0.2 | ^8.0 | ^8.0.0| | MIT | |
| v2.0.1 | ^8.0 | ^8.0.0| | MIT | |
| v2.0.0 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.51 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.50 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.49 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.48 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.47 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.46 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.45 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.44 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.43 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.42 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.41 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.40 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.39 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.38 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.37 | ^8.0 | ^8.0.0| | MIT | |
| v1.0.36 | ^8.0 | ^8.0.0| | MIT |
Showing the latest 30 of 62. See every release on Packagist