OTP Generator and Validator for Laravel Applications

Fund package maintenance!

0.0.7 2021-12-12 15:58 UTC

This package is auto-updated.

Last update: 2023-01-12 18:42:54 UTC


Latest Version on Packagist GitHub Tests Action Status Total Downloads


You can install the package via composer:

composer require seshac/otp-generator

You can publish and run the migrations with:

php artisan vendor:publish --provider="Seshac\Otp\OtpServiceProvider" --tag="migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="Seshac\Otp\OtpServiceProvider" --tag="config"


use Seshac\Otp\Otp;
$otp =  Otp::generate($identifier);
$verify = Otp::validate($identifier, $otp->token);
// example response
  "status": true
  "message": "OTP is valid"

// to get an expiredAt time
$expires = Otp::expiredAt($identifier);

// example response 
+"status": true
+"expired_at": Illuminate\Support\Carbon @1611895244^ {
  #dumpLocale: null
  date: 2021-01-29 04:40:44.0 UTC (+00:00)

You have control to update the setting at otp-generator.php config file but you control while generating also

Advance Usage

use Seshac\Otp\Otp;
$otp =  Otp::setValidity(30)  // otp validity time in mins
      ->setLength(4)  // Lenght of the generated otp
      ->setMaximumOtpsAllowed(10) // Number of times allowed to regenerate otps
      ->setOnlyDigits(false)  // generated otp contains mixed characters ex:ad2312
      ->setUseSameToken(true) // if you re-generate OTP, you will get same token
$verify = Otp::setAllowedAttempts(10) // number of times they can allow to attempt with wrong token
    ->validate($identifier, $otp->token);


composer test


Please see CHANGELOG for more information on what has changed recently.


Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.



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