farayaz/laravel-otp

simple otp for laravel

Maintainers

Package info

github.com/farayaz/laravel-otp

pkg:composer/farayaz/laravel-otp

Transparency log

Statistics

Installs: 82

Dependents: 0

Suggesters: 0

Stars: 9

Open Issues: 0

v2.0.0 2026-08-10 17:37 UTC

This package is auto-updated.

Last update: 2026-08-10 17:38:33 UTC


README

GitHub Repo stars Total Downloads Latest Stable Version License

simple laravel-otp package

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