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

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

elephant-php/otp
================

A small PHP library for generating one-time passwords and random verification codes.

0.1.0(1mo ago)02↓100%MITPHPPHP ^8.3

Since May 1Pushed 1mo agoCompare

[ Source](https://github.com/elephant-php/otp)[ Packagist](https://packagist.org/packages/elephant-php/otp)[ RSS](/packages/elephant-php-otp/feed)WikiDiscussions main Synced 1w ago

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

 [ ![elephant-php](elephant-php.webp) ](https://github.com/elephant-php/duration)

Elephant OTP
============

[](#elephant-otp)

A small PHP library for generating one-time passwords and random verification codes.

 [![Latest Version](https://camo.githubusercontent.com/9106c62d110a7f62bc81bdc17325eedae76d74a547fbbc72b182ba6aa4e2db26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c657068616e742d7068702f6f74702e737667)](https://packagist.org/packages/elephant-php/otp) [![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](./LICENSE.md) [![PHP 8.3+](https://camo.githubusercontent.com/c625f9110e52b20c52e78dd7521c1e7b4c925a48e85be6c2170469a618c9d2e9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d3737376262342e737667)](https://www.php.net/releases/8.3/en.php)

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

[](#installation)

```
composer require elephant-php/otp
```

Usage
-----

[](#usage)

Generate a default 6-character code:

```
use Elephant\Otp\OtpCode;

$code = new OtpCode()->generate();
```

Generate a code with a custom length:

```
use Elephant\Otp\OtpCode;

$code = new OtpCode()->generate(12);
```

Choose an alphabet:

```
use Elephant\Otp\Alphabet;
use Elephant\Otp\OtpCode;

$otp = new OtpCode();

$numeric = $otp->generate(alphabet: Alphabet::Numeric);      // 483920
$hex = $otp->generate(16, Alphabet::Hex);                    // 9f03a8c12b4e70df
$readable = $otp->generate(10, Alphabet::Readable);          // 7h4qz9x2wa
```

Alphabets
---------

[](#alphabets)

AlphabetCharacters`Alphabet::Numeric``0123456789``Alphabet::Hex``0123456789abcdef``Alphabet::Alpha``abcdefghijklmnopqrstuvwxyz``Alphabet::AlphaNumeric``abcdefghijklmnopqrstuvwxyz0123456789``Alphabet::Readable``23456789abcdefghijkmnpqrstuvwxyz``Alphabet::Readable` excludes visually ambiguous characters such as `0`, `1`, `l`, and `o`.

Invalid Length
--------------

[](#invalid-length)

Code length must be at least `1`. Invalid lengths throw `InvalidArgumentException`:

```
use Elephant\Otp\OtpCode;

new OtpCode()->generate(0); // throws InvalidArgumentException
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

MIT License.

Please see [`LICENSE`](./LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance92

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

39d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/98bd41d83d3ea8c774bfffa19be2323a844609643a8c4164bbb2ac9f74615923?d=identicon)[Pekhov Anton](/maintainers/Pekhov%20Anton)

---

Top Contributors

[![Pekhov14](https://avatars.githubusercontent.com/u/24500560?v=4)](https://github.com/Pekhov14 "Pekhov14 (3 commits)")

---

Tags

code-generatorone-time-codeone-time-passwordotpotp-generatorotp-libraryotp-verificationrandom-codeverification-codeotpcode generatorone-time-passwordverification Codeone-time coderandom code

### Embed Badge

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

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

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k116.2M670](/packages/symfony-maker-bundle)[hanneskod/classtools

Find, extract and process classes from file system

1309.2M40](/packages/hanneskod-classtools)[hiqdev/hidev

Automation tool mixed with code generator for easier continuous development

3029.6k28](/packages/hiqdev-hidev)[foryoufeng/laravel-generator

A tool for generate Laravel code file

712.8k](/packages/foryoufeng-laravel-generator)

PHPackages © 2026

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