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

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

danielrobert/otp-generator
==========================

A Laravel Package for Generating and Validating Otp using database

v1.08(1y ago)3857MITPHPPHP ^8.0CI passing

Since Mar 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/DanielRobert1/otp-generator)[ Packagist](https://packagist.org/packages/danielrobert/otp-generator)[ Docs](https://github.com/danielrobert/otp-generator)[ RSS](/packages/danielrobert-otp-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (10)Used By (0)

Otp Generator and Validator for Laravel Applications
====================================================

[](#otp-generator-and-validator-for-laravel-applications)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f71a3dbb768da6064acc9bb20304cb250bd135340ad9222753e1ec3b92bcc80c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616e69656c726f626572742f6f74702d67656e657261746f723f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/danielrobert1otp-generator)[![Quality Score](https://camo.githubusercontent.com/0dc2d6f5ecf550f5f54e063099f46b2e92f96cf5804b8cb32af46b967b47fb2a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f64616e69656c726f62657274312f6f74702d67656e657261746f722f6d61737465723f7374796c653d666f722d7468652d6261646765)](https://scrutinizer-ci.com/g/danielrobert1/otp-generator/)[![Code Quality](https://camo.githubusercontent.com/a2b0c20e15969f489530d03eb9ad2245edf09b37be167eab9ca6fb0397d3e08a/68747470733a2f2f696d672e736869656c64732e696f2f636f6465666163746f722f67726164652f6769746875622f64616e69656c726f62657274312f6f74702d67656e657261746f723f7374796c653d666f722d7468652d6261646765)](https://www.codefactor.io/repository/github/danielrobert1/otp-generator)[![Github Workflow Status](https://camo.githubusercontent.com/49b0d3c1d9a8fa05988a018abe2b39bd0a801b0e401750f66df44600475ceeef/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64616e69656c726f62657274312f6f74702d67656e657261746f722f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666f722d7468652d6261646765)](https://github.com/danielrobert1/otp-generator/actions/workflows/run-tests.yml)

[![Licence](https://camo.githubusercontent.com/ee9d5eae3015ad23e7dc81c085a3cd7d79888658c7d916223b031fc9d76333b1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f64616e69656c726f626572742f6f74702d67656e657261746f723f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/danielrobert/otp-generator)

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

[](#installation)

You may use the Composer package manager to install Otp Generator into your Laravel project:

```
composer require danielrobert/otp-generator
```

After installing the otp-generator, you need to publish its configuration and migration files. The migration files will be copied to your application's database/migrations directory, but they are not run automatically. You must run the migrate command yourself to create the necessary tables:

```
php artisan vendor:publish --provider="DanielRobert\Otp\OtpGeneratorServiceProvider" --tag=otp-migrations
php artisan vendor:publish --provider="DanielRobert\Otp\OtpGeneratorServiceProvider" --tag=otp-config
php artisan migrate
```

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

[](#configuration)

After publishing Otp Generator's configs, its primary configuration file will be located at config/otp-generator.php. This configuration file allows you to configure your otps. Each configuration option includes a description of its purpose, so be sure to thoroughly explore this file.

Data Pruning
------------

[](#data-pruning)

Data Pruning Without pruning, the otps table can accumulate records very quickly. To mitigate this, you can schedule the otp:prune Artisan command to run daily:

```
$schedule->command('otp:prune')->daily();
```

By default, all expired entries or entries older than 30 minutes as configured in the config/otp-generator.php will be pruned. You may use the minutes option when calling the command to determine how long to retain data. For example, the following command will delete all records created over 60 minutes ago:

```
$schedule->command('otp:prune --minutes=60')->daily();
```

Usage
-----

[](#usage)

```
use DanielRobert\Otp\Otp;
.
.
$otp =  Otp::generate($identifier);
.
$verify = Otp::validate($identifier, $otp->token);

// example response
{
  "status": true
  "message": "Otp is valid"
}

// to get an expiredAt time
$expires = Otp::expiredAt($identifier);

// example response
+"status": true
+"expired_at": Illuminate\Support\Carbon @1611895244^ {
  ....
  #dumpLocale: null
  date: 2021-01-29 04:40:44.0 UTC (+00:00)
}
```

Advance Usage
-------------

[](#advance-usage)

In addition to configuring otps from the otp-generator.php config file you can also configure it directly

```
use DanielRobert\Otp\Otp;
.
.
$otp =  Otp::setValidity(30)  // otp validity time in mins
      ->setLength(4)  // Lenght of the generated otp
      ->setMaximumOtpsAllowed(10) // Number of times allowed to regenerate otps
      ->setOnlyDigits(false)  // generated otp contains mixed characters ex:ad2312
      ->setUseSameToken(true) // if you re-generate Otp, you will get same token
      ->generate($identifier);
.
$verify = Otp::setAllowedAttempts(10) // number of times they can allow to attempt with wrong token
    ->validate($identifier, $otp->token);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Aigbe Daniel Robert](https://github.com/danielrobert1)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance48

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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 ~97 days

Recently: every ~194 days

Total

9

Last Release

379d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b969176e1d6d5ecd8e482977ec140da33030f0296b010ad9e51822392cb5c22d?d=identicon)[Daniel Robert Aigbe](/maintainers/Daniel%20Robert%20Aigbe)

---

Top Contributors

[![DanielRobert1](https://avatars.githubusercontent.com/u/71283099?v=4)](https://github.com/DanielRobert1 "DanielRobert1 (26 commits)")

---

Tags

laravelotp generatordanielrobertotp-sender

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4205.3M84](/packages/livewire-volt)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

97139.6k2](/packages/nickurt-laravel-akismet)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)[seshac/otp-generator

OTP Generator and Validator for Laravel Applications

42157.5k](/packages/seshac-otp-generator)

PHPackages © 2026

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