PHPackages                             graxmonzo/laravel-one-time-password - 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. graxmonzo/laravel-one-time-password

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

graxmonzo/laravel-one-time-password
===================================

One time password (OTP) generation trait for Laravel

1.1.1(5y ago)592MITPHPPHP ^7.4|^8.0

Since Jan 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/GraxMonzo/laravel-one-time-password)[ Packagist](https://packagist.org/packages/graxmonzo/laravel-one-time-password)[ Docs](https://github.com/graxmonzo/laravel-one-time-password)[ GitHub Sponsors](https://github.com/sponsors/graxmonzo)[ Fund](https://paypal.me/bkzts)[ RSS](/packages/graxmonzo-laravel-one-time-password/feed)WikiDiscussions master Synced 1mo ago

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

laravel-one-time-password
=========================

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/a6534045532761526e1444cc4513678900af522bfe8eae8fbc4f184aa9546fac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677261786d6f6e7a6f2f6c61726176656c2d6f6e652d74696d652d70617373776f72642e737667)](https://packagist.org/packages/graxmonzo/laravel-one-time-password)[![GitHub Tests Action Status](https://camo.githubusercontent.com/2ff2e2e0faaea125e26ded8ecc5be542d8ad777f78bf572fd2b4ca9219fb480d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f677261786d6f6e7a6f2f6c61726176656c2d6f6e652d74696d652d70617373776f72642f54657374733f6c6162656c3d7465737473)](https://github.com/graxmonzo/laravel-one-time-password/actions?query=workflow%3ATests+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/362086ddc0fe1092a3d985ced96a34be67ecfcccde22e7e1881134402b5a8716/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677261786d6f6e7a6f2f6c61726176656c2d6f6e652d74696d652d70617373776f72642e737667)](https://packagist.org/packages/graxmonzo/laravel-one-time-password)

Laravel implementation of Rails's [active\_model\_otp](https://github.com/heapsource/active_model_otp/) package.

Simple OTP generation.

```
$code = $user->otp(); // => "324650"
$user->verify($code); // => true
$user->verify($code); // => false
```

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

[](#installation)

You can install the package via composer:

```
composer require graxmonzo/laravel-one-time-password
```

Usage
-----

[](#usage)

Your Eloquent models should use the `GraxMonzo\OneTimePassWord\HasOTP` trait and the `GraxMonzo\OneTimePassWord\OTPOptions` class.

The trait contains an abstract method `otpOptions()` that you must implement yourself.

Your models' migrations should have a fields to save the OTP secret and counter to.

Here's an example of how to implement the trait:

```
namespace App;

use GraxMonzo\OneTimePassword\HasOTP;
use GraxMonzo\OneTimePassword\OTPOptions;
use Illuminate\Database\Eloquent\Model;

class YourEloquentModel extends Model
{
    use HasOTP;

    /**
     * Get the options for generating OTP.
     */
    public function otpOptions() : OTPOptions
    {
        return OTPOptions::create()
            ->saveToFields('otp_secret', 'otp_counter')
            ->digitsCount(6); // optional
    }
}
```

With its migration:

```
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateYourEloquentModelTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('your_eloquent_models', function (Blueprint $table) {
            $table->increments('id');
            $table->string('otp_secret');
            $table->integer('otp_counter');
            $table->timestamps();
        });
    }
}
```

### Get code

[](#get-code)

```
$model = new YourEloquentModel();

$model->otp(); # => "186522"
$code = $model->otp(); # => "850738"
```

### Verify code

[](#verify-code)

```
$model->verify($code); # => true
$model->verify($code); # => false
```

### Verify code with counter adjust

[](#verify-code-with-counter-adjust)

```
$model->verify($code); # => true
$model->otp_counter -= 1;
$model->verify($code); # => true
```

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)

- [GraxMonzo](https://github.com/graxmonzo)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

5

Last Release

1940d ago

Major Versions

0.1.1 → 1.0.02021-01-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c95182f489ae6fb8333d205fed7a6df088058ddd15eb4b768186e6c09916ff7?d=identicon)[GraxMonzo](/maintainers/GraxMonzo)

---

Top Contributors

[![GraxMonzo](https://avatars.githubusercontent.com/u/11737104?v=4)](https://github.com/GraxMonzo "GraxMonzo (30 commits)")

---

Tags

hotplaravellaravel-hotplaravel-one-time-passwordlaravel-otpone-time-passwordotpotpone-time-passwordgraxmonzolaravel-one-time-password

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/graxmonzo-laravel-one-time-password/health.svg)

```
[![Health](https://phpackages.com/badges/graxmonzo-laravel-one-time-password/health.svg)](https://phpackages.com/packages/graxmonzo-laravel-one-time-password)
```

###  Alternatives

[fouladgar/laravel-otp

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

21426.5k](/packages/fouladgar-laravel-otp)[remotemerge/totp-php

Lightweight, fast, and secure TOTP (2FA) authentication library for PHP — battle tested, dependency free, and ready for enterprise integration.

2010.2k](/packages/remotemerge-totp-php)

PHPackages © 2026

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