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

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

shrikant/otp
============

A framework-agnostic OTP generator and validator

1.0.0(10mo ago)02MITPHPPHP &gt;=7.4CI failing

Since Jul 8Pushed 10mo agoCompare

[ Source](https://github.com/Shrikant-28/OTP-Package)[ Packagist](https://packagist.org/packages/shrikant/otp)[ RSS](/packages/shrikant-otp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (6)Used By (0)

📂 Git Repo: `otp`
-----------------

[](#-git-repo-otp)

### Directory Tree

[](#directory-tree)

```
otp/
├── src/
│   ├── OTP.php
│   └── Storage/
│       └── OTPStoreInterface.php
├── tests/
│   └── OTPTest.php
├── composer.json
├── README.md
├── .gitignore
└── phpunit.xml

```

---

📘 README.md
-----------

[](#-readmemd)

```
# OTP

**Framework-Agnostic One Time Password (OTP) Generator and Validator for PHP**

---

## 🚀 Features

- ✅ Generate numeric OTPs (default 6 digits)
- ✅ Validate OTPs
- ✅ TTL (expiration time) support
- ✅ Framework-agnostic (works with Laravel, Symfony, Slim, etc.)
- ✅ Pluggable storage (memory, session, database)

---

## 📦 Installation

```bash
composer require shrikant/otp
```

---

🛠️ Usage
--------

[](#️-usage)

```
use Shrikant\OTP\OTP;
use Shrikant\OTP\Storage\OTPStoreInterface;

class SessionStore implements OTPStoreInterface {
    public function set(string $key, string $otp, int $ttl): void {
        $_SESSION[$key] = ['otp' => $otp, 'expires' => time() + $ttl];
    }

    public function get(string $key): ?string {
        return ($_SESSION[$key]['expires'] ?? 0) > time()
            ? $_SESSION[$key]['otp']
            : null;
    }

    public function delete(string $key): void {
        unset($_SESSION[$key]);
    }
}

session_start();
$otpService = new OTP(new SessionStore());

$otp = $otpService->generate('user:email', 6, 300); // Generate 6-digit OTP valid for 5 minutes

// Later...
if ($otpService->validate('user:email', $_POST['otp'])) {
    echo "Valid!";
} else {
    echo "Invalid!";
}
```

---

✅ Testing
---------

[](#-testing)

```
composer install
./vendor/bin/phpunit
```

---

🔌 Extending
-----------

[](#-extending)

Implement `OTPStoreInterface` to use Redis, Database, Cache, etc.

```
interface OTPStoreInterface {
    public function set(string $key, string $otp, int $ttl): void;
    public function get(string $key): ?string;
    public function delete(string $key): void;
}
```

---

📄 License
---------

[](#-license)

MIT License. Do what you want.

---

❤️ Contributing
---------------

[](#️-contributing)

Pull requests and issues are welcome!!!

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance54

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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

Unknown

Total

1

Last Release

315d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4522701c2df9ccd4693fb3341c1205a4b4066644a902eea347ffad80b3eb7bf9?d=identicon)[shrikant-28](/maintainers/shrikant-28)

---

Top Contributors

[![Shrikant-28](https://avatars.githubusercontent.com/u/59720723?v=4)](https://github.com/Shrikant-28 "Shrikant-28 (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[gpslab/domain-event-bundle

Bundle to create the domain layer of your DDD application

1427.1k](/packages/gpslab-domain-event-bundle)[dev-lnk/laravel-code-builder

Generate classes and files from table schema

194.7k](/packages/dev-lnk-laravel-code-builder)

PHPackages © 2026

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