dcvn/otp-laravel is a Laravel package for laravel layer for local otp authentication.
It currently has 1 GitHub stars and 13 downloads on Packagist (latest version v1.0.0).
Install it with composer require dcvn/otp-laravel.
Discover more Laravel packages by dcvn
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel layer for local OTP authentication.
This is an attempt to make OTP implementation in Laravel easy.
Being a layer, this could not exist without these core dependencies:
Being local, otp-laravel does, by default, not depend on network services to generate QR codes (with thanks to the offline example of RobThree using phpqrcode).
Follow the Quickstart to setup a new Laravel project using this OTP package.
The most important part is, in the LoginController,
to replace the existing use AuthenticatesUsers
to use Dcvn\Otp\Http\Controllers\AuthenticatesUsers;.
If you feel real lazy, copy this quickstart.sh script to the base dir of your projects, and run it (at your own risk).
Assuming using the quickstart way, but you can implement how you like it.
otp_secret column to the users table (migration)..env.OneTimePassword as alias in the app.<?php
$otp = OneTimePassword::configured();
if ($otp->verifyCode($user->otp_secret), $request->verification) { /* ... */ }
You don't necessarily need this, but you can copy config, language or view files to your project this way:
artisan vendor:publish --provider "Dcvn\Otp\Providers\OtpServiceProvider" --tag config
artisan vendor:publish --provider "Dcvn\Otp\Providers\OtpServiceProvider" --tag lang
artisan vendor:publish --provider "Dcvn\Otp\Providers\OtpServiceProvider" --tag views
To override the access policy
(for example to allow (only) admin users to do the setup),
copy this to your AuthServiceProvider's boot() method,
then modify it:
<?php
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Gate;
// in boot():
Gate::define('otp.setup', function (Authenticatable $user, Authenticatable $model) {
return $user->id == $model->id;
});