jeremykenedy/laravel2step is a Laravel package for laravel 2 step authentication package.
It currently has 281 GitHub stars and 112.886 downloads on Packagist (latest version v6.0.0).
Install it with composer require jeremykenedy/laravel2step.
Discover more Laravel packages by jeremykenedy
or browse all Laravel packages to compare alternatives.
Last updated
Laravel 2-Step Verification is a package to add 2-Step user authentication to any Laravel project easily. It is configurable and customizable. It uses notifications to send the user an email with a 4-digit verification code. Can be used in out the box with Laravel's authentication scaffolding or integrated into other projects.
Table of contents:
| Laravel 2 Step Verification Features | | :------------ | | Uses Notification Class to send user code to users email | | Can publish customizable views and assets | | Lots of configuration options | | Uses Language localization files | | Verificaton Page | | Locked Page |
From your projects root folder in terminal run:
Laravel 6+ use:
composer require jeremykenedy/laravel2step
Laravel 5.8 use:
composer require jeremykenedy/laravel2step:v1.4.0
Laravel 5.7 and below use:
composer require jeremykenedy/laravel2step:v1.0.2
Register the package
Laravel 5.5 and up
Uses package auto discovery feature, no need to edit the config/app.php file.
Laravel 5.4 and below
Register the package with laravel in config/app.php under providers with the following:
'providers' => [
jeremykenedy\laravel2step\laravel2stepServiceProvider::class,
];
php artisan vendor:publish --tag=laravel2step
Optionally Update your .env file and associated settings (see Environment File section)
Run the migration to add the verifications codes table:
php artisan migrate
.env file with the needed configuration variables..env file.Laravel 2-Step Verification can be configured in directly in /config/laravel2step.php or in the variables in your .env file.
Here are the .env file variables available:
LARAVEL_2STEP_ENABLED=true
LARAVEL_2STEP_DATABASE_TABLE=laravel2step
LARAVEL_2STEP_USER_MODEL=App\Models\User
LARAVEL_2STEP_EMAIL_FROM_NAME="Laravel 2 Step Verification"
LARAVEL_2STEP_EXCEEDED_COUNT=3
LARAVEL_2STEP_EXCEEDED_COUNTDOWN_MINUTES=1440
LARAVEL_2STEP_VERIFIED_LIFETIME_MINUTES=360
LARAVEL_2STEP_RESET_BUFFER_IN_SECONDS=360
LARAVEL_2STEP_CSS_FILE="css/laravel2step/app.css"
LARAVEL_2STEP_APP_CSS_ENABLED=false
LARAVEL_2STEP_APP_CSS="css/app.css"
LARAVEL_2STEP_BOOTSTRAP_CSS_CDN_ENABLED=true
LARAVEL_2STEP_BOOTSTRAP_CSS_CDN="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"
# Optional. Defaults to your application's default database connection.
# LARAVEL_2STEP_DATABASE_CONNECTION=mysql
# Optional. Defaults to your application's MAIL_FROM_ADDRESS.
# LARAVEL_2STEP_EMAIL_FROM="[email protected]"
# Optional. Send the verification email on a named queue.
# LARAVEL_2STEP_EMAIL_QUEUE=notifications
Laravel 2-Step Verification is enabled via middleware. You can enable 2-Step Verification in your routes and controllers via the following middleware:
twostep
Example to start recording page views using middlware in web.php:
Route::group(['middleware' => ['twostep']], function () {
Route::get('/home', 'HomeController@index')->name('home');
});
Two step verification is supported on your application's default guard, which is Laravel's session based web guard unless you changed it. The twostep middleware needs a session, since it stores where the user was headed, so it belongs on routes in the web group.
If you protect web group routes with another guard, for example ['auth:sanctum', 'twostep'], an unverified user is still blocked, because Laravel's middleware priority runs auth ahead of this package's middleware. That user cannot complete verification though: /verification/needed authenticates on the default guard, so they are sent to your login route instead of the verification form.
/verification/needed/verification/verify/verification/resendThe package ships with a Pest suite that runs against an in memory SQLite database, so it never touches a real database.
composer install
composer test
Running the suite needs PHP 8.2 or higher, because Pest and Pint do not run on anything older. That is a requirement for working on the package, not for using it: the package itself still installs on PHP 7.3 and up.
Code style is checked with Laravel Pint:
composer lint
GitHub Actions runs on every pull request, on pushes to master, and again every Monday so a new Laravel release cannot break the package quietly:
| Job | What it covers |
| :--- | :--- |
| Tests | Laravel 12 on PHP 8.2 to 8.5, Laravel 13 on PHP 8.3 to 8.5 |
| Lowest dependencies | The oldest dependency versions that resolve against Laravel 12 |
| Code style | composer validate --strict and pint --test |
| Security audit | composer audit against known advisories |
Laravel 11 and below are still supported by the composer constraints, but they cannot be installed on a clean runner anymore, because composer blocks the framework releases that carry published security advisories.

└── laravel2step
├── .gitattributes
├── .github
│ ├── dependabot.yml
│ ├── FUNDING.yml
│ └── workflows
│ └── tests.yml
├── .gitignore
├── .scrutinizer.yml
├── art
│ ├── banner-dark.svg
│ └── banner-light.svg
├── composer.json
├── LICENSE
├── phpunit.xml
├── pint.json
├── README.md
├── src
│ ├── .env.example
│ ├── App
│ │ ├── Http
│ │ │ ├── Controllers
│ │ │ │ └── TwoStepController.php
│ │ │ └── Middleware
│ │ │ └── Laravel2step.php
│ │ ├── Models
│ │ │ └── TwoStepAuth.php
│ │ ├── Notifications
│ │ │ └── SendVerificationCodeEmail.php
│ │ └── Traits
│ │ └── Laravel2StepTrait.php
│ ├── config
│ │ └── laravel2step.php
│ ├── database
│ │ └── migrations
│ │ └── 2017_12_09_070937_create_two_step_auth_table.php
│ ├── Laravel2stepFacade.php
│ ├── Laravel2stepServiceProvider.php
│ ├── public
│ │ └── css
│ │ ├── app.css
│ │ └── app.min.css
│ ├── resources
│ │ ├── assets
│ │ │ └── scss
│ │ │ ├── _animations.scss
│ │ │ ├── _mixins.scss
│ │ │ ├── _modals.scss
│ │ │ ├── _variables.scss
│ │ │ ├── _verification.scss
│ │ │ └── app.scss
│ │ ├── lang
│ │ │ └── en
│ │ │ └── laravel-verification.php
│ │ └── views
│ │ ├── layouts
│ │ │ └── app.blade.php
│ │ ├── scripts
│ │ │ └── input-parsing-auto-stepper.blade.php
│ │ └── twostep
│ │ ├── exceeded.blade.php
│ │ └── verification.blade.php
│ └── routes
│ └── web.php
└── tests
├── Feature
│ ├── MiddlewareTest.php
│ ├── SendVerificationCodeEmailTest.php
│ └── TwoStepControllerTest.php
├── Models
│ └── User.php
├── Pest.php
├── Support
│ ├── RouteSpy.php
│ └── TwoStepTester.php
├── TestCase.php
└── Unit
├── ConfigTest.php
├── Laravel2StepTraitTest.php
├── ServiceProviderTest.php
└── TwoStepAuthModelTest.php
brew install treetree -a -I '.git|node_modules|vendor|storage|composer.lock'Before opening an issue there are a couple of considerations:
Open source projects are a the community’s responsibility to use, contribute, and debug.
Laravel 2-Step Verification is licensed under the MIT license. Enjoy!