Looking to hire Laravel developers? Try LaraJobs

laravel-otp maintained by farayaz

Description
simple otp for laravel
Author
Last update
2026/08/10 19:37 (dev-main)
License
Links
Downloads
121

Comments
comments powered by Disqus

Usage

$otp = OTP::generate('user@example.com');

OTP::isValid('user@example.com', $otp->code); // checks without consuming
OTP::validate('user@example.com', $otp->code); // checks and consumes atomically

All rejected OTPs (wrong, expired, already used, or attempt-locked) throw the same Farayaz\LaravelOtp\Exceptions\LaravelOtpException with the message Invalid OTP.

Publish the optional configuration file with:

php artisan vendor:publish --tag=laravel-otp-config

It configures the default code length (6), validity in minutes (5), and maximum failed attempts (3). Explicit generate() arguments take precedence over these defaults. Supported OTP lengths are 3 through 10 digits, and validity must be a positive integer number of minutes.

Upgrading

Run php artisan migrate after upgrading. The additive package migration adds the persistent attempts column and a unique identifier index. Test installations with duplicate identifier rows must remove those duplicates before migrating. Generating an OTP then atomically replaces the existing OTP state for that identifier.

Compatibility

  • Laravel 10
  • Laravel 11
  • Laravel 12
  • Laravel 13