PHPackages                             mkd/laravel-advanced-otp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. mkd/laravel-advanced-otp

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

mkd/laravel-advanced-otp
========================

An advanced, customizable OTP (One-Time Password) verification system for Laravel applications, supporting hashed token and custom validation methods.

v1.0.1(1y ago)107MITPHPPHP ^8.0

Since Oct 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mustafakhaleddev/LaravelAdvancedOTP)[ Packagist](https://packagist.org/packages/mkd/laravel-advanced-otp)[ Docs](https://github.com/mustafakhaleddev/laravel-advanced-otp)[ RSS](/packages/mkd-laravel-advanced-otp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Laravel Advanced OTP
====================

[](#laravel-advanced-otp)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0d459597fb23a5c8f1befcb4dbf2548d2ff94c6f2a0f9be9e96bba97be7e75f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6b642f6c61726176656c2d616476616e6365642d6f74702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mkdev/laravel-advanced-otp)[![Total Downloads](https://camo.githubusercontent.com/fcc054edcd5f12fd8a1f0c5de800640574c3088cb91e8934ebbbdb406f1cea5c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6b642f6c61726176656c2d616476616e6365642d6f74702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mkdev/laravel-advanced-otp)[![GitHub Actions](https://github.com/mustafakhaleddev/LaravelAdvancedOTP/actions/workflows/main.yml/badge.svg)](https://github.com/mustafakhaleddev/LaravelAdvancedOTP/actions/workflows/main.yml/badge.svg)

Laravel Advanced OTP is a package designed for flexible OTP (One-Time Password) verification, supporting both hashed token verification and custom validation methods. It allows for easy OTP handling for tasks like email-based authentication.

---

Features
--------

[](#features)

- **Hashed Token Verification**: Secure OTP validation using hashed tokens.
- **Custom Validation**: Developers can use their own validation methods (e.g., database or cache-based).
- **Configurable OTP Settings**: Custom timeout and OTP length.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require mkd/laravel-advanced-otp
```

Create your own OTPMethod

```
php artisan magic-otp:make LoginOTP
```

Usage
-----

[](#usage)

### 1. OTP Generation and Email Sending (Hashed Token)

[](#1-otp-generation-and-email-sending-hashed-token)

In this example, a hashed token is used to securely send and verify the OTP.

```
// Generate OTP and send it via email
$otp = \LaravelAdvancedOTP::handle(LoginOTP::class, [
    'secret' => 'secret_key',  // Required to hash and verify OTP
    'email' => 'user_email@example.com',  // Email of the recipient
]);

// Get the hashed token for verification
$token = $otp->getHashedKey();

// Send OTP to user's email
$otp->send('user_email@example.com');

// Return the hashed token for later verification
return response()->json(['token' => $token]);
```

### 2. OTP Generation Without Hashed Token

[](#2-otp-generation-without-hashed-token)

If you want to handle the OTP validation manually (e.g., store it in a database or cache), you can omit the hashed token.

```
// Generate and send OTP without hashed token
\LaravelAdvancedOTP::handle(LoginOTP::class)->send('user_email@example.com');
```

### 3. Verifying OTP (Hashed Token)

[](#3-verifying-otp-hashed-token)

Use the hashed token to validate the OTP.

```
$otp = request('otp');
$hashedToken = request('token');  // Token returned when sending OTP

$signature = [
    'secret' => 'secret_key',  // Same secret used during OTP generation
    'email' => 'user_email@example.com',
];

// Verify the OTP using the hashed token
$otpStatus = \LaravelAdvancedOTP::verify(LoginOTP::class, $otp, $signature, $hashedToken);

if ($otpStatus == OTPStatusEnum::NOT_VERIFIED) {
    // OTP is invalid
}

if ($otpStatus == OTPStatusEnum::VERIFIED) {
    // OTP is valid
}

if ($otpStatus == OTPStatusEnum::EXPIRED) {
    // OTP has expired
}
```

### 4. Verifying OTP (Custom Validation)

[](#4-verifying-otp-custom-validation)

If you want to handle OTP validation manually, you can use your custom logic for verification.

```
$otp = request('otp');
$email = request('email');

// Custom validation for OTP
$otpVerified = \LaravelAdvancedOTP::validate(LoginOTP::class, $otp, $email);

if ($otpVerified) {
    // OTP is valid
} else {
    // OTP is invalid or expired
}
```

Custom OTP Class
----------------

[](#custom-otp-class)

To implement your OTP logic, create a class extending `MagicOTP`. Here is an example:

```
class LoginOTP extends MagicOTP
{
    protected int $timeout = 120;  // Timeout in seconds
    protected int $otpLength = 5;  // Length of the OTP

    public function send($email)
    {
        $otp = $this->getOTP();
        // Logic to send OTP via email
    }

    public function validate($otp, $email)
    {
        // Logic to validate OTP for the email
    }
}
```

Configuration
-------------

[](#configuration)

You can adjust the default settings like OTP timeout, length, and more by customizing your OTP class.

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Mustafa Khaled](https://github.com/mkdev)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

579d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25182746?v=4)[Mustafa Khaled](/maintainers/mustafakhaleddev)[@mustafakhaleddev](https://github.com/mustafakhaleddev)

---

Top Contributors

[![mustafakhaleddev](https://avatars.githubusercontent.com/u/25182746?v=4)](https://github.com/mustafakhaleddev "mustafakhaleddev (11 commits)")

---

Tags

advanced-laravel-otphashed-otplaravellaravel-frameworklaravel-hashed-otplaravel-otplaravel-packagelaravelotpotpotp-generatorotp-libraryotp-verificationotpauthsecurity-otplaravelotpAuthentication2faTwo Factor Authenticationlaravel-packageone-time-passwordemail-verificationlaravel otpotp verificationToken verificationadvanced otplaravel otp verificationmkdevlaravel-advanced-otp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mkd-laravel-advanced-otp/health.svg)

```
[![Health](https://phpackages.com/badges/mkd-laravel-advanced-otp/health.svg)](https://phpackages.com/packages/mkd-laravel-advanced-otp)
```

###  Alternatives

[tzsk/otp

A secure, database-free One-Time Password (OTP) generator and verifier for PHP and Laravel.

241641.4k1](/packages/tzsk-otp)[ellaisys/aws-cognito

AWS Cognito package that allows Auth and other related features using the AWS SDK for PHP

120220.7k1](/packages/ellaisys-aws-cognito)[remotemerge/totp-php

Lightweight, fast, and secure TOTP (2FA) authentication library for PHP — battle tested, dependency free, and ready for enterprise integration.

2010.2k](/packages/remotemerge-totp-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
