viezel/otp

One Time Password for Laravel

1.0.0 2020-10-23 13:44 UTC

This package is auto-updated.

Last update: 2024-11-29 06:22:17 UTC


README

Latest Version on Packagist GitHub Tests Action Status Type Coverage

This package is sending out a 6 digit verification code per email, when a user visits a route in your Laravel app. By default, the user identity verification will be valid for 30 minutes.

Verify

Installation

  1. Install the package via composer:
composer require viezel/otp
php artisan vendor:publish --provider="Viezel\OTP\OTPServiceProvider" --tag="migrations"
php artisan migrate
  1. Add Middleware check_otp to the routes that should verify the User Identity.
Route::get('some/protected/route', MyController::class)->middleware(['auth', 'check_otp']);
Route::get('other/route', MyOtherController::class)->middleware(['auth', 'check_otp']);

Config

You can publish the config file with:

php artisan vendor:publish --provider="Viezel\OTP\OTPServiceProvider" --tag="otp-config"
return [
    /*
     * How long time in minutes should the verification code be valid for
     */
    'link_expires_in_minutes' => 300,

    /*
     * How long time in minutes should the user be verified for the certain route
     */
    'validation_expires_after_minutes' => 30,

    /*
     * Should be use the queue to sent out the verification email
     */
    'use_queue' => false,

    /*
     * Route Prefix
     */
    'route_prefix' => '',

    /*
     * Route Middleware
     */
    'route_middleware' => ['web', 'auth'],
];

Customize

You can build up your own verification view. Just publish the views and change what you need.

The package provides a blade component to reuse. Its based on Alpine.js and Tailwind CSS.

<x-otp::pincode url="{{ $url }}"></x-otp::pincode>

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.