PHPackages                             rahmatwaisi/otp-auth - 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. [Framework](/categories/framework)
4. /
5. rahmatwaisi/otp-auth

ActiveLibrary[Framework](/categories/framework)

rahmatwaisi/otp-auth
====================

Easily Generate and Verify an OTP using laravel cache

v1.0.2(2y ago)15MITPHPPHP ^8.0.2

Since Sep 13Pushed 2y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (6)Used By (0)

One Time Password - OTP
=======================

[](#one-time-password---otp)

[![rahmatwaisi-otp-auth](https://camo.githubusercontent.com/fa757b9de35dd0483b6f0c843801fda3ecb0b4751d19d2b2a02bd6a0ac0c9455/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532304f54502532302e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d7261686d617477616973692532466f74702d61757468267061747465726e3d68657861676f6e73267374796c653d7374796c655f31266465736372697074696f6e3d456173696c792b67656e65726174652b616e642b7665726966792b616e2b4f54502b7573696e672b4c61726176656c2b6361636865266d643d322673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/fa757b9de35dd0483b6f0c843801fda3ecb0b4751d19d2b2a02bd6a0ac0c9455/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532304f54502532302e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d7261686d617477616973692532466f74702d61757468267061747465726e3d68657861676f6e73267374796c653d7374796c655f31266465736372697074696f6e3d456173696c792b67656e65726174652b616e642b7665726966792b616e2b4f54502b7573696e672b4c61726176656c2b6361636865266d643d322673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e4139288dc9c310e0a5eddc099a83135eceb955a6057ca8337a8280eae4fa7ca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7261686d617477616973692f6f74702d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rahmatwaisi/otp-auth)[![Total Downloads](https://camo.githubusercontent.com/f52d7fe3e61a3ac322c220208f7d655cfbaffe3ec58149a6e5a5f4967f13cf2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7261686d617477616973692f6f74702d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rahmatwaisi/otp-auth)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/d4a2627599ee3c6425cbdf2c59fb5060f6b1ea56d0cf66dee76c60059bbcc099/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f6170702e6368697070657263692e636f6d2f70726f6a656374732f37356138303736372d383763372d343838362d386338312d6433666438303432336232612f7374617475732f6d61696e267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d4a2627599ee3c6425cbdf2c59fb5060f6b1ea56d0cf66dee76c60059bbcc099/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f6170702e6368697070657263692e636f6d2f70726f6a656374732f37356138303736372d383763372d343838362d386338312d6433666438303432336232612f7374617475732f6d61696e267374796c653d666c61742d737175617265)

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

[](#installation)

You can install the package with Composer.

```
composer require rahmatwaisi/otp-auth
```

Usage
-----

[](#usage)

### Creating an OTP

[](#creating-an-otp)

#### All you need is to use the `OtpGenerator` facade as below:

[](#all-you-need-is-to-use-the-otpgenerator-facade-as-below)

```
use RahmatWaisi\OtpAuth\Facades\OtpGenerator;
use RahmatWaisi\OtpAuth\Core\OtpType;
.
.
// To Create a new OTP using a key like User::$id or User::$email, etc.
$otp = OtpGenerator::create('key') // output: 234234
```

#### Another more customizeable way is to determine prefix, key, ttl, length, type, etc.

[](#another-more-customizeable-way-is-to-determine-prefix-key-ttl-length-type-etc)

```
$user = User::query()->inRandomOrder()->first();

$otp = OtpGenerator::createFrom('smth',  $user->id) // output: 234234, a 6-digit integer

$otp = OtpGenerator::createFrom('smth',  $user->email, OtpType::NUMBER) // output: 234234, a 6-digit integer

$otp = OtpGenerator::createFrom('smth',  $user->username, OtpType::STRING) // output: "aBcDeF", a 6-char string

$otp = OtpGenerator::createFrom('smth',  $user->custom_key, OtpType::NUMBER, 12, now()->addDay()) // output: 123321234234, a 12-digit integer

$otp = OtpGenerator::createFrom('smth',  $user->whatever, OtpType::STRING, 8, now()->addDay()) // output: "aBcdEfgH", an 8-char string
```

> All codes above are using the publishable configs in the package which are located in configs/otp.php

#### Another way that you can customize any configs in the runtime is:

[](#another-way-that-you-can-customize-any-configs-in-the-runtime-is)

```
$otp = OtpGenerator::builder()
    ->withPrefix('dummy_prefix')
    ->withKey('my_custom_key')
    ->withType(OtpType::NUMBER)
    ->withTtl(now()->addMinutes(2))
    ->withLength(8)
    ->build();

// Output: 12345678, an 8-digit integer
```

### Resolving, Validating, Removing an OTP

[](#resolving-validating-removing-an-otp)

#### All you need is to use the `OtpGenerator` facade as below:

[](#all-you-need-is-to-use-the-otpgenerator-facade-as-below-1)

```
use RahmatWaisi\OtpAuth\Facades\OtpGenerator;
use RahmatWaisi\OtpAuth\Core\OtpType;
.
.
// To Remove, Forget or Resolve an OTP using a key like User::$id or User::$email, etc. Do like this:

// Forgets the OTP just using the key
OtpGenerator::forget($user->id);

// Checks wether an incoming OTP from request exists or not?
OtpGenerator::verify($user->id, request()->get('otp'));
OtpGenerator::verifyUsing('custom_prefix', $user->id, request()->get('otp'));

// Removes an OTP using both key and its value
OtpGenerator::remove($key, 'aBcDeFgH');

// Gets an OTP just using the key
OtpGenerator::get($key);
OtpGenerator::get($user->username);
```

#### Another more customizeable way is to determine prefix, key, ttl, length, type, etc.

[](#another-more-customizeable-way-is-to-determine-prefix-key-ttl-length-type-etc-1)

```
$user = User::query()->inRandomOrder()->first();

// Get an OTP just using the key and default configs
OtpGenerator::resolver()->withDefaultSettings()->withKey($user->id)->resolve();

// Forgets an OTP just using the key and default configs
OtpGenerator::resolver()->withDefaultSettings()->withKey($user->id)->forget();

// Checks for existence of an OTP just using the key and default configs
OtpGenerator::resolver()->withDefaultSettings()->withKey($user->id)->exists(request()->get('otp'));

// Get an OTP just using the key and default prefix
OtpGenerator::resolver()->withDefaultPrefix()->withKey($user->id)->resolve();

//  Checks for existence of an OTP just using the key and default perfix
OtpGenerator::resolver()->withDefaultPrefix()->withKey($user->id)->exists(request()->get('otp'));
```

> All codes above are using the publishable configs in the package which are located in configs/otp.php

#### Another way that you can customize any configs in the runtime is:

[](#another-way-that-you-can-customize-any-configs-in-the-runtime-is-1)

```
// Get an OTP just using the key and custom prefix
$otp = OtpGenerator::resolver()
    ->withPrefix('smth')
    ->withKey($user->id)
    ->resolve();
```

Conclusion
----------

[](#conclusion)

By using this package you can easily creat and validate any form with any length of OTPs.

Contribution
------------

[](#contribution)

Feel free to suggest improvements, I'll appreciate any contribution from anyone. Thank you.

Made with 💙 In a late late night.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Total

3

Last Release

968d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/23fb0b121595fbd966129e1d6bd8af68001cbc7b6ce079fe964af9936f65dd9e?d=identicon)[Rahmat Waisi](/maintainers/Rahmat%20Waisi)

---

Top Contributors

[![rahmatwaisi](https://avatars.githubusercontent.com/u/20902452?v=4)](https://github.com/rahmatwaisi "rahmatwaisi (35 commits)")

---

Tags

laravellaravel-otpotpotp-generatorotp-verificationpackageframeworklaravelotpauthlaravel-packageLaravel Authlaravel otpotp-authrahmatwaisi otp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laravel/jetstream

Tailwind scaffolding for the Laravel framework.

4.1k19.8M136](/packages/laravel-jetstream)[rebing/graphql-laravel

Laravel wrapper for PHP GraphQL

2.2k7.1M26](/packages/rebing-graphql-laravel)[graham-campbell/markdown

Markdown Is A CommonMark Wrapper For Laravel

1.3k7.1M64](/packages/graham-campbell-markdown)[graham-campbell/manager

Manager Provides Some Manager Functionality For Laravel

39221.1M134](/packages/graham-campbell-manager)[laravel-lang/publisher

Localization publisher for your Laravel application

2167.7M24](/packages/laravel-lang-publisher)[milwad/laravel-validate

The Laravel-Validate package enhanced Laravel validation capabilities with custom rules and methods for simplified and efficient validation logic.

59739.5k1](/packages/milwad-laravel-validate)

PHPackages © 2026

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