PHPackages                             blamodex/laravel-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. blamodex/laravel-otp

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

blamodex/laravel-otp
====================

A simple, Laravel-ready one-time password (OTP) package for rapid prototyping and lightweight use cases.

v1.0.0(5mo ago)2561MITPHPPHP ^8.2CI passing

Since Nov 1Pushed 5mo agoCompare

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

READMEChangelog (1)Dependencies (11)Versions (4)Used By (0)

Blamodex Laravel OTP
====================

[](#blamodex-laravel-otp)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bc61774a3d0015eb6fcf3df58734365b887313494d915c8ad403b7d7cf923868/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626c616d6f6465782f6c61726176656c2d6f74702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/blamodex/laravel-otp)[![GitHub Tests Action Status](https://camo.githubusercontent.com/f95f604c1f829e68b5653d0951bb43e06f89d8d3e5c81e0e9d06b912fd61f7b9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f626c616d6f6465782f6c61726176656c2d6f74702f63692e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/blamodex/laravel-otp/actions)[![Total Downloads](https://camo.githubusercontent.com/06514b0161acad4a9ee6f8f9bde6c9c88bf87dcc992077a710e31947b2561fb4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626c616d6f6465782f6c61726176656c2d6f74702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/blamodex/laravel-otp)[![License](https://camo.githubusercontent.com/1b01ef0024ba0866c115986b895301f657c1b21fc29f05c4844b7f2e8d89204d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666c61742d737175617265)](https://opensource.org/licenses/MIT)[![Laravel](https://camo.githubusercontent.com/28258179aab3740537de18650134eb68e8c5f1f7396109f5bcfd29ddf28bb4d8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322d7265642e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)[![PHP](https://camo.githubusercontent.com/6d0e63bb9482df87aa6c6ea983969a625be703cd8cfc3460c99eb1e582e6b46f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d626c75652e7376673f7374796c653d666c61742d737175617265)](https://www.php.net/)

A lightweight Laravel package to add one-time password (OTP) capabilities to any Eloquent model using polymorphic relationships.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#-features)
- [Installation](#-installation)
- [Configuration](#%EF%B8%8F-configuration)
- [Usage](#-usage)
- [Testing](#-testing)
- [Project Structure](#-project-structure)
- [Contributing](#-contributing)
- [License](#-license)

---

🚀 Features
----------

[](#-features)

- Attach OTP functionality to any model using a trait
- Polymorphic support for multiple model types
- Configurable alphabet, length, expiry, and hash algorithm
- Secure hashing via `password_hash` and `password_verify`
- Auto-expiration and one-time use enforcement
- Clean architecture: trait, model, service, generator

---

📦 Installation
--------------

[](#-installation)

Install the package with Composer:

```
composer require blamodex/laravel-otp
```

Publish the config file:

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

Run the migrations:

```
php artisan migrate
```

---

⚙️ Configuration
----------------

[](#️-configuration)

Configuration lives in `config/otp.php`:

```
return [
    /* PASSWORD ALGORITHM, SEE https://www.php.net/manual/en/function.password-hash.php FOR MORE INFO */
    'algorithm' => PASSWORD_BCRYPT,

    /* PASSWORD ALPHABET */

    //NUMBERS ONLY ALPHABET
    'alphabet' => '0123456789',

    //"WORD SAFE" ALPHABET
    //'alphabet' => '256789BCDFGHJKMNPQRSTVXW',

    //ALPHANUM ALPHABET
    //'alphabet' => '0123456789ABCDEFGHIJKLMNOPQRSTUV';

    /* PASSWORD LENGTH */
    'length' => 6,

    /* PASSWORD EXPIRY */
    'expiry' => 600
];
```

---

🧩 Usage
-------

[](#-usage)

### 1. Implement the interface and use the trait

[](#1-implement-the-interface-and-use-the-trait)

```
use Blamodex\Otp\Traits\OneTimePasswordable;
use Blamodex\Otp\Contracts\OneTimePasswordableInterface;

class User extends Model implements OneTimePasswordableInterface
{
    use OneTimePasswordable;
}
```

### 2. Generate an OTP

[](#2-generate-an-otp)

```
$user = User::find(1);
$otp = $user->generateOtp(); // returns raw password
```

### 3. Verify an OTP

[](#3-verify-an-otp)

```
if ($user->verifyOtp('123456')) {
    // Success
} else {
    // Failure
}
```

---

🧪 Testing
---------

[](#-testing)

This package uses [Orchestra Testbench](https://github.com/orchestral/testbench) and [PHPUnit](https://phpunit.de/).

Run tests:

```
composer test
```

Check code style:

```
composer lint
```

Check code style and fix:

```
composer lint:fix
```

Check coverage (with Xdebug):

```
composer test:coverage
```

---

📁 Project Structure
-------------------

[](#-project-structure)

```
src/
├── Models/
│   └── OneTimePassword.php
├── Data/
│   └── OtpData.php
├── Services/
│   ├── OtpGenerator.php
│   └── OtpService.php
├── Traits/
│   └── OneTimePasswordable.php
├── Contracts/
│   └── OneTimePasswordableInterface.php
├── config/
│   └── otp.php
└── database/
    └── migrations/
        └── 202x_xx_xx_create_one_time_passwords_table.php

tests/
├── Unit/
├── Fixtures/
└── TestCase.php

```

---

🤝 Contributing
--------------

[](#-contributing)

We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

---

📝 Changelog
-----------

[](#-changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for recent changes.

---

📄 License
---------

[](#-license)

MIT © [Blamodex](https://github.com/blamodex)

For more information, see the [LICENSE](LICENSE) file.

---

🔗 Links
-------

[](#-links)

- [Report a Bug](https://github.com/blamodex/laravel-otp/issues)
- [Request a Feature](https://github.com/blamodex/laravel-otp/issues)
- [View Changelog](CHANGELOG.md)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance71

Regular maintenance activity

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.2% 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

Unknown

Total

1

Last Release

164d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f55d38385fa6cea42e03e9f4d95bbb789c6c0492de1e386b60e5f2836c96d5d?d=identicon)[blamodex](/maintainers/blamodex)

---

Top Contributors

[![blackmage-codex](https://avatars.githubusercontent.com/u/218423009?v=4)](https://github.com/blackmage-codex "blackmage-codex (52 commits)")[![patoui](https://avatars.githubusercontent.com/u/4511175?v=4)](https://github.com/patoui "patoui (19 commits)")

---

Tags

laravelotpsecurityAuthentication2faverificationone-time-password

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[laragear/two-factor

On-premises 2FA Authentication for out-of-the-box.

339785.3k8](/packages/laragear-two-factor)[alajusticia/laravel-logins

Session management in Laravel apps, user notifications on new access, support for multiple separate remember tokens, IP geolocation, User-Agent parser

2011.0k](/packages/alajusticia-laravel-logins)[rinvex/laravel-authy

Rinvex Authy is a simple wrapper for Authy TOTP, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.

3376.7k1](/packages/rinvex-laravel-authy)[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)[sicaboy/laravel-mfa

A Laravel package of Multi-factor Authentication (MFA/2FA) with a middleware.

101.2k](/packages/sicaboy-laravel-mfa)

PHPackages © 2026

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