PHPackages                             putheakhem/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. putheakhem/laravel-otp

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

putheakhem/laravel-otp
======================

A simple OTP generator for Laravel

0.0.3(1y ago)11MITPHPPHP ^8.3.0CI failing

Since Feb 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/putheakhem/otp)[ Packagist](https://packagist.org/packages/putheakhem/laravel-otp)[ GitHub Sponsors](https://github.com/putheakhem)[ Patreon](https://www.patreon.com/putheakhem)[ RSS](/packages/putheakhem-laravel-otp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (4)Used By (0)

Laravel OTP Package - `putheakhem/otp`
======================================

[](#laravel-otp-package---putheakhemotp)

[![Tests](https://github.com/putheakhem/otp/actions/workflows/tests.yml/badge.svg)](https://github.com/putheakhem/otp/actions/workflows/tests.yml)

A Laravel package for generating, validating, and managing One-Time Passwords (OTP) with security features.

---

📌 Features
----------

[](#-features)

- ✅ Rate-limited OTP generation
- ✅ Configurable expiration times
- ✅ Invalidate OTP after first use
- ✅ Lock OTP to user session
- ✅ Invalidate OTP after too many failed attempts
- ✅ View detailed error messages
- ✅ Customizable mail template
- ✅ Auditable logs for security

---

🔧 Installation
--------------

[](#-installation)

### 1️⃣ Install via Composer

[](#1️⃣-install-via-composer)

```
composer require putheakhem/otp
```

### 2️⃣ Publish Configuration &amp; Migrations

[](#2️⃣-publish-configuration--migrations)

```
php artisan vendor:publish --provider="PutheaKhem\Otp\Providers\OtpServiceProvider"
php artisan migrate
```

This will create:

- A **config file** at `config/otp.php`
- A **database table** `otps`

---

### **3 Configuration**

[](#3-configuration)

Modify `config/otp.php` to adjust settings:

```
return [
    'length' => 6, // OTP length
    'expires_in' => 300, // OTP expiration time in seconds (5 minutes)
    'max_attempts' => 5, // Maximum failed attempts before invalidation
    'lock_to_session' => true, // OTP tied to user session
    'mail_template' => 'otp::emails.otp', // Email template for OTP
    'logging_enabled' => true, // Enable OTP logging
];
```

---

🔥 Usage
-------

[](#-usage)

### **Generate an OTP**

[](#generate-an-otp)

```
use PutheaKhem\Otp\Facades\Otp;

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

dd($otp);
```

📌 **Output Example:**

```
PutheaKhem\Otp\Models\Otp {#123
  id: 1,
  identifier: "user@example.com",
  otp: "123456",
  used: false,
  attempts: 0,
  expires_at: "2025-02-10 12:00:00"
}
```

---

### **Validate an OTP**

[](#validate-an-otp)

```
$response = Otp::validate('user@example.com', '123456');

dd($response);
```

📌 **Expected Output:**✅ **Success**

```
{
    "status": true,
    "message": "OTP verified successfully."
}
```

❌ **Failure (Invalid OTP)**

```
{
    "status": false,
    "message": "Invalid OTP."
}
```

❌ **Failure (Expired OTP)**

```
{
    "status": false,
    "message": "OTP expired or invalid."
}
```

---

📩 Email Customization
---------------------

[](#-email-customization)

Customize the email template at:

```
resources/views/vendor/otp/emails/otp.blade.php

```

Example:

```

    OTP Verification

    Your OTP is: {{ $otp }}
    This OTP is valid for {{ config('otp.expires_in') / 60 }} minutes.

```

---

🔬 Testing
---------

[](#-testing)

### **Run All Tests**

[](#run-all-tests)

```
php artisan test
```

📌 **Expected Output:**

```
✔ can generate OTP
✔ can validate OTP
✔ OTP invalid after expiry
✔ OTP fails after too many attempts
✔ OTP logs events
✔ Emails are sent correctly
✔ OTP is locked to session

```

---

📢 Contributing
--------------

[](#-contributing)

1. Fork the repository
2. Clone the repo: ```
    git clone https://github.com/putheakhem/otp.git
    ```
3. Create a new branch: ```
    git checkout -b feature-branch
    ```
4. Commit changes &amp; push: ```
    git commit -m "Added new feature"
    git push origin feature-branch
    ```
5. Submit a **Pull Request** 🚀

---

🏆 Credits
---------

[](#-credits)

Developed by **[Puthea Khem](https://github.com/putheakhem)**.
Special thanks to the **Laravel community**! 🎉

---

📜 License
---------

[](#-license)

This package is open-source and licensed under the **MIT License**.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance43

Moderate activity, may be stable

Popularity3

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

3

Last Release

453d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/764935335a012f6477a36e9bf81144d2c887becfbd0dea300426a27f7677ab93?d=identicon)[putheakhem](/maintainers/putheakhem)

---

Top Contributors

[![putheakhem](https://avatars.githubusercontent.com/u/8064772?v=4)](https://github.com/putheakhem "putheakhem (7 commits)")

---

Tags

generatorlaravelotpphplaravelotp

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[amranidev/laracombee

Recommendation system for laravel

11636.7k1](/packages/amranidev-laracombee)[salmanzafar/laravel-geocode

A Laravel Library to find Lat and Long of a given Specific Address

153.9k](/packages/salmanzafar-laravel-geocode)[wujunze/money-wrapper

MoneyPHP Wrapper

113.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

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