PHPackages                             bonabrian/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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. bonabrian/laravel-otp

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

bonabrian/laravel-otp
=====================

Laravel OTP generator and validator without using database

1.0.0(5y ago)10MITPHPPHP ^7.3

Since Oct 20Pushed 5y ago1 watchersCompare

[ Source](https://github.com/bonabrian/laravel-otp)[ Packagist](https://packagist.org/packages/bonabrian/laravel-otp)[ Docs](https://github.com/bonabrian/laravel-otp)[ RSS](/packages/bonabrian-laravel-otp/feed)WikiDiscussions main Synced 2d ago

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

OTP Generator &amp; Validator
=============================

[](#otp-generator--validator)

[![Github License](https://camo.githubusercontent.com/ec20c766818c59d02c72fb84fd0c8190149871394e03b410b2a9cfe8936228dd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f626f6e61627269616e2f6c61726176656c2d6f74703f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/ec20c766818c59d02c72fb84fd0c8190149871394e03b410b2a9cfe8936228dd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f626f6e61627269616e2f6c61726176656c2d6f74703f7374796c653d666f722d7468652d6261646765)

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

[](#installation)

Via Composer

```
composer require bonabrian/laravel-otp
```

To publish the config file for laravel

```
php artisan otp:publish
```

Usage in Laravel
----------------

[](#usage-in-laravel)

Import the facade class

```
use Bonabrian\Otp\Facades\Otp;
```

**Generate an OTP:**

```
$code = Otp::generate($secret);
```

The generated OTP above will only be validated using the same secret within the default expiry time.

> **TIP:** OTP is generally used for verification. So the easiest way of determining the `secret` is the user's email/username or phone number or maybe user ID.

**Validate an OTP:**

```
$valid = Otp::validate($code, $secret);
```

**Other Generate &amp; Validate options:**

```
// Generate
Otp::setDigits(4)->generate($secret); // 4 Digits
Otp::setExpiry(30)->generate($secret); // 30 min expiry
Otp::setDigits(4)->setExpiry(30)->generate($secret); // 4 Digits, 30 min expiry
```

Make sure to set the same config during validating. Example:

```
// Example 1
Otp::validate($code, $secret); // false
Otp::setDigits(4)->validate($code, $secret); // true

// Example 2
Otp::validate($code, $secret); // false
Otp::setExpiry(30)->validate($codde, $secret); // true

// Example 3
Otp::validate($code, $secret); // false
Otp::setDigits(4)->setExpiry(30)->validate($code, $secret); // true
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

2031d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/14372275?v=4)[Bona Brian Siagian](/maintainers/bonabrian)[@bonabrian](https://github.com/bonabrian)

---

Top Contributors

[![bonabrian](https://avatars.githubusercontent.com/u/14372275?v=4)](https://github.com/bonabrian "bonabrian (18 commits)")

---

Tags

otplaravel otpphp otpotp without database

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spomky-labs/otphp

A PHP library for generating one time passwords according to RFC 4226 (HOTP Algorithm) and the RFC 6238 (TOTP Algorithm) and compatible with Google Authenticator

1.5k46.1M119](/packages/spomky-labs-otphp)[tzsk/otp

A secure, database-free One-Time Password (OTP) generator and verifier for PHP and Laravel.

241641.4k1](/packages/tzsk-otp)[fouladgar/laravel-otp

This package provides convenient methods for sending and validating OTP notifications to users for authentication.

21426.5k](/packages/fouladgar-laravel-otp)[salehhashemi/laravel-otp-manager

Laravel OTP manager

18713.2k](/packages/salehhashemi-laravel-otp-manager)[chillerlan/php-authenticator

A generator for counter- and time based 2-factor authentication codes (Google Authenticator). PHP 8.2+

58119.1k2](/packages/chillerlan-php-authenticator)[teckwei1993/laravel-otp

Laravel OTP generator and validation

5556.0k](/packages/teckwei1993-laravel-otp)

PHPackages © 2026

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