fisal/laravel-otp

A simple package to generate and validate OTPs (internal fork with improvements)

Maintainers

Package info

github.com/muuFisal/fisal-laravel-otp

pkg:composer/fisal/laravel-otp

Statistics

Installs: 23

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.3 2026-02-13 00:18 UTC

This package is auto-updated.

Last update: 2026-03-13 00:37:26 UTC


README

A lightweight Laravel package to generate and validate one-time passwords (OTPs).

This is a maintained fork intended for real projects: it adds OTP type binding (e.g. login, 2fa) and an attempts limit.

Installation

composer require fisal/laravel-otp:^1.0

Configuration (optional)

Publish config (optional):

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

Then you can control max attempts via:

  • config/otp.php
  • or env: OTP_MAX_ATTEMPTS=5

Usage

Generate OTP

use Otp;

// tokenType: numeric | alpha_numeric
// otpType: purpose binding (login | 2fa | reset_password | ...)
$result = Otp::generate(
    identifier: '201001234567',
    tokenType: 'numeric',
    length: 6,
    validity: 5,
    otpType: 'login'
);

$token = $result->token;

Validate OTP (consumes on success)

$result = Otp::validate(
    identifier: '201001234567',
    token: '123456',
    otpType: 'login'
);

if ($result->status) {
    // valid
} else {
    // invalid / expired
    // optional: $result->remaining_attempts
}

Boolean check (does NOT consume)

$isValid = Otp::isValid('201001234567', '123456', 'login');

Artisan

Clean invalid and expired OTPs:

php artisan otp:clean

License

MIT