brians84/two-factor-auth-laravel is a Laravel package for a package to handle 2fa authentication.
It currently has 0 GitHub stars and 28 downloads on Packagist.
Install it with composer require brians84/two-factor-auth-laravel.
Discover more Laravel packages by brians84
or browse all Laravel packages to compare alternatives.
Last updated
A simple 2FA that uses Google Authenticator.
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.


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.
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\TwoFactorAuthMiddleware where you need it.
[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 :)
}
[optional] Disable this package in local environments by adding TWO_FACTOR_AUTH_ENABLED=false in 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,
Project Link: https://github.com/maurohmartinez/two-factor-auth-laravel