PHPackages                             ars/laravel-otp-code - 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. ars/laravel-otp-code

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

ars/laravel-otp-code
====================

A Laravel package for generating, validating, and managing One-Time Passwords (OTPs) to enhance security in authentication workflows.

v1.1.0(1y ago)645MITPHPPHP &gt;=8.0

Since Aug 19Pushed 1y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (3)Used By (0)

OTP Code Laravel - One-Time Password In Laravel
===============================================

[](#otp-code-laravel---one-time-password-in-laravel)

Introduction
------------

[](#introduction)

This Laravel package offers a comprehensive solution for generating, storing, and verifying One-Time Passwords (OTPs). It supports customizable OTP configurations, including type, length, expiration, encryption, and validation rules, ensuring secure and flexible OTP management in your Laravel applications.

Features
--------

[](#features)

- Generate secure OTP codes with customizable types and lengths.
- Store and manage OTP codes with configurable expiration times.
- Optional OTP encryption for enhanced security.
- Validation rules to ensure OTP integrity.
- Seamless integration with Laravel applications.

Requirements:
-------------

[](#requirements)

- Laravel Version: 10 or higher
- PHP Version: 8.0 or higher

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

[](#installation)

To install the package, follow these steps:

1. **Require the package via Composer**:

    ```
    composer require ars/laravel-otp-code
    ```
2. **Publish the configuration file and migration**:

    ```
    php artisan vendor:publish --provider="Ars\Otp\Providers\OtpCodeServiceProvider"
    ```
3. **Run the migration**:

    ```
    php artisan migrate
    ```

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

[](#configuration)

The configuration file `otp-code.php` includes the following options:

- **`table_name`**: The name of the database table to store OTP codes.
- **`code_type`**: The data type of the OTP code (`int` for integers or `string` for alphanumeric).
- **`code_length`**: The length of the OTP code.
- **`max_attempts`**: The maximum number of attempts allowed to validate the OTP (set `0` to disable attempts).
- **`expiry_time`**: The time (in minutes) before the OTP expires.
- **`encrypt_code`**: Whether to encrypt the OTP code before storing it.
- **`default_salt`**: The default salt value to be used if none is provided.

Usage
-----

[](#usage)

### Repository

[](#repository)

#### Creating an OTP

[](#creating-an-otp)

To create an OTP, use the `create` method:

```
$otpRepository = new \Ars\Otp\Repositories\OtpRepository();
$otp = $otpRepository->create('alireza2000sajedi@gmail.com');
$code = $otp->code;
```

#### Verifying an OTP

[](#verifying-an-otp)

To verify an OTP, use the `verify` method:

```
$isValid = $otpRepository->verify('alireza2000sajedi@gmail.com', 1234);
```

#### Checking OTP Existence

[](#checking-otp-existence)

To check if a valid OTP exists, use the `has` method:

```
$exists = $otpRepository->has('alireza2000sajedi@gmail.com');
```

### Facade

[](#facade)

The package provides a facade for easy access to the OTP repository:

```
use Ars\Otp\Facades\OtpCode;

// Create OTP
$otp = OtpCode::create('alireza2000sajedi@gmail.com');
$code = $otp->code;
// Verify OTP
$isValid = OtpCode::verify('alireza2000sajedi@gmail.com', 1234);
```

### Custom Validation Rule

[](#custom-validation-rule)

The package includes a validation rule to validate OTP codes:

```
use Ars\Otp\Rules\OtpCode;

$request->validate([
    'email' => 'alireza2000sajedi@gmail.com',
    'otp_code' => ['required', new OtpCode($request->get('email'))],
]);
```

Example
-------

[](#example)

```
use Ars\Otp\Facades\OtpCode;

    //If has salt send parameter after identifier
    public function sendOtp($email, $salt = null)
    {
        if (OtpCode::has($email, $salt)) {
            return Responder::setErrorCode(201)->setMessage(trans('otp_code::otp-code.already_send'))->respond();
        }

        $otp = OtpCode::create($email, $salt);

        Notification::send($email, new OtpNotification($otp->code));
    }
```

Customization
-------------

[](#customization)

### Error Messages

[](#error-messages)

You can customize the error messages by modifying the language files. Publish the language files using:

```
php artisan vendor:publish --tag=lang --provider="Ars\Otp\Providers\OtpCodeServiceProvider"
```

### Commands

[](#commands)

The package includes an Artisan command to purge expired OTP codes:

```
php artisan otp:clear-expired
```

Conclusion
----------

[](#conclusion)

This package provides a robust solution for managing OTP codes in a Laravel application. By leveraging the repository, facade, and validation rules, you can easily integrate OTP functionality into your project.

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

[](#contributing)

Contributions are welcome! Please adhere to the following guidelines:

1. Fork the repository.
2. Create a feature branch (git checkout -b feature/my-new-feature).
3. Commit your changes (git commit -am 'Add new feature').
4. Push to the branch (git push origin feature/my-new-feature).
5. Open a Pull Request.

License
-------

[](#license)

This library is licensed under the MIT License.

Contact
-------

[](#contact)

For support or questions, please open an issue on GitHub.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

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

2

Last Release

628d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/06fa4d332d575f1bcee0f091115409cbae2070d1b519e4e0e44f00ee7fc58c6e?d=identicon)[alireza2000sajedi](/maintainers/alireza2000sajedi)

---

Top Contributors

[![alireza2000sajedi](https://avatars.githubusercontent.com/u/36206809?v=4)](https://github.com/alireza2000sajedi "alireza2000sajedi (13 commits)")

---

Tags

laravelotpsecurityAuthentication2faTwo Factor Authenticationlaravel-packageone-time-passwordphp-package

### Embed Badge

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

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

###  Alternatives

[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)[hosseinhezami/laravel-permission-manager

Advanced permission manager for Laravel.

403.3k](/packages/hosseinhezami-laravel-permission-manager)

PHPackages © 2026

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