PHPackages                             ferdous/laravel-otp-validate - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. ferdous/laravel-otp-validate

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

ferdous/laravel-otp-validate
============================

Laravel package for OTP validation with built-in features like retry and resend mechanism. Built in max retry and max resend blocking. OTP/Security Code can be send over SMS or Email of your choice with user-defined template.

v2.0.2(3y ago)7124.4k↓50%14[5 issues](https://github.com/ferdousulhaque/laravel-otp-validate/issues)MITPHPPHP ^7.4|^8.0

Since Aug 2Pushed 2y ago5 watchersCompare

[ Source](https://github.com/ferdousulhaque/laravel-otp-validate)[ Packagist](https://packagist.org/packages/ferdous/laravel-otp-validate)[ Docs](https://github.com/ferdousulhaque/laravel-otp-validate)[ RSS](/packages/ferdous-laravel-otp-validate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (4)Versions (9)Used By (0)

OTP Validate Package in Laravel
===============================

[](#otp-validate-package-in-laravel)

[![Packagist Downloads](https://camo.githubusercontent.com/f4bae4a63b12ade0ed5b27ac4eeb2111eafa021713eed3a208685d1cffe884cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666572646f75732f6c61726176656c2d6f74702d76616c6964617465)](https://camo.githubusercontent.com/f4bae4a63b12ade0ed5b27ac4eeb2111eafa021713eed3a208685d1cffe884cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666572646f75732f6c61726176656c2d6f74702d76616c6964617465)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)[![Packagist Version](https://camo.githubusercontent.com/685a1e13e4432c1283757c45bb595ccfe43b0cc83075bf2686962d7488314d03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666572646f75732f6c61726176656c2d6f74702d76616c6964617465)](https://camo.githubusercontent.com/685a1e13e4432c1283757c45bb595ccfe43b0cc83075bf2686962d7488314d03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666572646f75732f6c61726176656c2d6f74702d76616c6964617465)[![Packagist PHP Version Support](https://camo.githubusercontent.com/468ffa06311c5fb18cf070268d8c842a4a2acdef959a5ae0569f84c9bb61e923/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f666572646f75732f6c61726176656c2d6f74702d76616c6964617465)](https://camo.githubusercontent.com/468ffa06311c5fb18cf070268d8c842a4a2acdef959a5ae0569f84c9bb61e923/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f666572646f75732f6c61726176656c2d6f74702d76616c6964617465)[![GitHub code size in bytes](https://camo.githubusercontent.com/91f10c20245bab43bc22619b4dd75c851239cfa5ee3b024f7cda560073e645b6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f666572646f7573756c68617175652f6c61726176656c2d6f74702d76616c6964617465)](https://camo.githubusercontent.com/91f10c20245bab43bc22619b4dd75c851239cfa5ee3b024f7cda560073e645b6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f666572646f7573756c68617175652f6c61726176656c2d6f74702d76616c6964617465)

This package is for easy setup for OTP validation process. No hassle, just plug and play. Following the steps mentioned below and you will be able to get a fully working OTP Validation system. You can use this later for authentication or e-commerce production selling, order confirmation.

[!["Buy Me A Coffee"](https://camo.githubusercontent.com/9f44ce2dc3b3eecdd02598900866ffc518801df1932849703dae1e5ce5031070/68747470733a2f2f7777772e6275796d6561636f666665652e636f6d2f6173736574732f696d672f637573746f6d5f696d616765732f6f72616e67655f696d672e706e67)](https://www.buymeacoffee.com/ferdousulhaque)

Major change from version v2.0.1
--------------------------------

[](#major-change-from-version-v201)

Only Supports 7.4 and above &amp; 8.0 and above, so any PHP versions below users will need to upgrade to use the latest version onwards.

- PHP version 7.4 and above
- PHP version 8.0 and above

If you are using PHP 7.4 below, please use version v1.4.0.

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

[](#installation)

### Install Package

[](#install-package)

Require this package with composer:

```
composer require ferdous/laravel-otp-validate

```

### Add Service Provider &amp; Facade

[](#add-service-provider--facade)

#### For Laravel 5.5+

[](#for-laravel-55)

Once the package is added, the service provider and facade will be auto discovered.

#### For Older versions of Laravel

[](#for-older-versions-of-laravel)

Add the ServiceProvider to the providers array in `config/app.php`:

```
Ferdous\OtpValidator\OtpValidatorServiceProvider::class
```

Add the Facade to the aliases array in `config/app.php`:

```
'OtpValidator' => Ferdous\OtpValidator\OtpValidatorServiceProvider::class
```

Publish Config
--------------

[](#publish-config)

Once done, publish the config to your config folder using:

```
php artisan vendor:publish --provider="Ferdous\OtpValidator\OtpValidatorServiceProvider"

```

This command will create a `config/otp.php` file.

### Email Configs

[](#email-configs)

From the `.env` file the email configs are setup. No other changes required.

See the `otp.php` file for optional customizations such as the ability to specify a custom `Mailable` class.

### SMS Configs

[](#sms-configs)

As the SMS Gateways use different methods and also extra headers and params, you may need to update the sms configs in the `otp.php` file.

Migrate Database
----------------

[](#migrate-database)

Run the following command to create the otps table.

```
php artisan migrate

```

It will create a otps table with the required columns.

Environment
-----------

[](#environment)

Add the following Key-Value pair to the `.env` file in the Laravel application

```
# Basic OTP Configs
OTP_SERVICE='enabled'
OTP_TABLE_NAME='otps'
OTP_TIMEOUT=120
OTP_DIGIT=5
OTP_RESEND_SERVICE='enabled'
OTP_MAX_RETRY=2
OTP_MAX_RESEND=1
# Company and Service
OTP_SERVICE_NAME=
OTP_COMPANY_NAME=
# OTP via Email / SMS
OTP_SEND_BY_EMAIL=1
OTP_SEND_BY_SMS=1
# Email Configurations
OTP_EMAIL_FROM=
OTP_EMAIL_FROM_NAME=
OTP_EMAIL_SUBJECT=
# SMS Configurations
OTP_SMSC_URL='https://sms'
OTP_SMSC_METHOD=
OTP_COUNTRY_CODE=
OTP_SMSC_OVER_JSON=
OTP_SMSC_PARAM_TO_NAME=
OTP_SMSC_PARAM_MSG_NAME=
OTP_SMSC_USER=
OTP_SMSC_PASS=
AWS_SNS_VERSION=
AWS_SNS_KEY=
AWS_SNS_SECRET=
AWS_SNS_REGION=

```

Definitions
-----------

[](#definitions)

Definition of the features in config are:

- service : enable/disable OTP Service
- timeout: timeout for OTP
- digit: OTP Digit
- resend-service: enable/disable resend Service
- max-retry: max retry for a single request
- max-resend: max resend for a single request
- service-name: for which the service is used
- company-name: for which company
- send-by: there are 3 ways to share otp (Email/SMS/AWS SNS)
- email: this key specifies the required information for email (e.g. from, name, subject etc.)
- sms: configure with SMS gateway to send SMS. (Universal Configurator)

Defining Send By on Runtime
---------------------------

[](#defining-send-by-on-runtime)

The config method can be used to set send-by \[ SMS / Email / SNS \] at runtime.

```
config('otp.send-by.email', 1);
config('otp.send-by.sms', 0);

```

OTP Request Templates
---------------------

[](#otp-request-templates)

Once the template files are published, open `resources/views/vendor/template-otp/`

Sample Controller
-----------------

[](#sample-controller)

Run the following command to create a controller.

`php artisan make:controller OtpController`

Below is a sample for calling the OTP Validator in OtpController.

```
namespace App\Http\Controllers;

use Ferdous\OtpValidator\Object\OtpRequestObject;
use Ferdous\OtpValidator\OtpValidator;
use Ferdous\OtpValidator\Object\OtpValidateRequestObject;

class OtpController extends Controller
{
    /**
     * @return array
     */
    public function requestForOtp()
    {
        return OtpValidator::requestOtp(
            new OtpRequestObject('1432', 'buy-shirt', '01711084714', 'ferdousul.haque@gmail.com')
        );
    }

    /**
     * @param Request $request
     * @return array
     */
    public function validateOtp(Request $request)
    {
        $uniqId = $request->input('uniqueId');
        $otp = $request->input('otp');
        return OtpValidator::validateOtp(
            new OtpValidateRequestObject($uniqId,$otp)
        );
    }

    /**
     * @param Request $request
     * @return array
     */
    public function resendOtp(Request $request)
    {
        $uniqueId = $request->input('uniqueId');
        return OtpValidator::resendOtp($uniqueId);
    }

}
```

Add the following to the `routes/web.php` file.

```
Route::get('/test/otp-request', [\App\Http\Controllers\OtpController::class, 'requestForOtp']);
Route::get('/test/otp-validate', [\App\Http\Controllers\OtpController::class, 'validateOtp']);
Route::get('/test/otp-resend', [\App\Http\Controllers\OtpController::class, 'resendOtp']);

```

Response/Error Descriptions
---------------------------

[](#responseerror-descriptions)

The below table describes the error codes generated in the response and their corresponding meanings.

```
{
  "code": 201,
  "message": "OTP Sent to the recipient",
  "requestId": 1432,
  "type": "buy-shirt"
}
```

#### Request OTP Response Codes

[](#request-otp-response-codes)

CodeMeanings201Successfully Generated OTP and shared.400Bad request.501Resend Service Disabled.503Service Unavailable.#### OTP Validate Response Codes

[](#otp-validate-response-codes)

CodeMeanings200Correct OTP.400Invalid OTP.404OTP Expired/Not Found.413Max Retry Exceeded.License
-------

[](#license)

MIT

Special Thanks
--------------

[](#special-thanks)

- [Nahid Bin Azhar](https://github.com/nahid) For the Feedback.

Support
-------

[](#support)

- For any bugs, please help to create an issue.
- For any problem installing or configurations, feel free to knock me.

Featured Article
----------------

[](#featured-article)

- [How to create a laravel OTP/Security code verification for e-commerce website](https://medium.com/@ferdousul.haque/how-to-create-a-laravel-otp-security-code-verification-for-e-commerce-website-55de8161cfb8)

Example SMS Gateways Configuration
----------------------------------

[](#example-sms-gateways-configuration)

### [Muthofun](https://www.muthofun.com/)

[](#muthofun)

If you are trying to integrate one of most popular SMS gateway of Bangladesh, muthofun is a popular Bulk SMS Gateway in our country. Here is a sample configuration for the Muthofun SMS Gateway

```
'smsc' => [
    'url' => env('OTP_SMSC_URL'),
    'method' => env('OTP_SMSC_METHOD', 'GET'),
    'add_code' => env('OTP_COUNTRY_CODE',null),
    'json' => env('OTP_SMSC_OVER_JSON',1),
    'headers' => [],
    'params' => [
        'send_to_param_name' => env('OTP_SMSC_PARAM_TO_NAME','number'),
        'msg_param_name' => env('OTP_SMSC_PARAM_MSG_NAME','msg'),
        'others' => [
            'user' => env('OTP_SMSC_USER'),
            'password' => env('OTP_SMSC_PASS'),
            'unicode' => 1
        ],
    ]
];
```

.env file will be as the following

```
OTP_SMSC_URL='http://clients.muthofun.com:8901/esmsgw/sendsms.jsp?'
OTP_SMSC_METHOD='GET'
OTP_COUNTRY_CODE='88'
OTP_SMSC_OVER_JSON=0
OTP_SMSC_PARAM_TO_NAME='mobiles'
OTP_SMSC_PARAM_MSG_NAME='sms'
OTP_SMSC_USER='YourUserName'
OTP_SMSC_PASS='YourPassWord'

```

### [Infobip](https://www.infobip.com/)

[](#infobip)

Example for integrating with the infobip SMS platform, renowned SMS Gateway.

using GET method

```
'smsc' => [
    'url' => env('OTP_SMSC_URL'),
    'method' => env('OTP_SMSC_METHOD', 'GET'),
    'add_code' => env('OTP_COUNTRY_CODE',null),
    'json' => env('OTP_SMSC_OVER_JSON',1),
    'headers' => [],
    'params' => [
        'send_to_param_name' => env('OTP_SMSC_PARAM_TO_NAME','number'),
        'msg_param_name' => env('OTP_SMSC_PARAM_MSG_NAME','msg'),
        'others' => [
            'username' => env('OTP_SMSC_USER'),
            'password' => env('OTP_SMSC_PASS'),
            'from' => 'InfoSMS',
            'flash' => true
        ],
    ]
];
```

.env file will be as the following

```
OTP_SMSC_URL='https://{baseUrl}/sms/1/text/query?'
OTP_SMSC_METHOD='GET'
OTP_COUNTRY_CODE='88'
OTP_SMSC_OVER_JSON=0
OTP_SMSC_PARAM_TO_NAME='to'
OTP_SMSC_PARAM_MSG_NAME='text'
OTP_SMSC_USER='YourUserName'
OTP_SMSC_PASS='YourPassWord'

```

### [msg91](https://msg91.com)

[](#msg91)

Sample for integrating with the msg91 SMS gateway.

using GET method

```
'smsc' => [
        'url' => env('OTP_SMSC_URL'),
        'method' => env('OTP_SMSC_METHOD', 'GET'),
        'add_code' => env('OTP_COUNTRY_CODE',null),
        'json' => env('OTP_SMSC_OVER_JSON',1),
        'headers' => [],
        'params' => [
            'send_to_param_name' => env('OTP_SMSC_PARAM_TO_NAME','number'),
            'msg_param_name' => env('OTP_SMSC_PARAM_MSG_NAME','msg'),
            'others' => [
                'authkey' => 'YourAuthKey',
                'sender' => 'YourSenderId',
                'route' => '1',
                'country' => '88',
            ],
        ],
        'wrapper' => 'sms',
    ];
```

.env file will be as the following

```
OTP_SMSC_URL='https://control.msg91.com/api/v2/sendsms?'
OTP_SMSC_METHOD='POST'
OTP_COUNTRY_CODE='88'
OTP_SMSC_OVER_JSON=1
OTP_SMSC_PARAM_TO_NAME='to'
OTP_SMSC_PARAM_MSG_NAME='text'
OTP_SMSC_USER='YourUserName'
OTP_SMSC_PASS='YourPassWord'

```

### [Using AWS Simple Notification Service (SNS)](https://aws.amazon.com/sns/)

[](#using-aws-simple-notification-service-sns)

Sample steps for integrating with the AWS SNS.

Create a IAM user with the appropriate policy permissions. Go to the IAM service and create your application’s user; be sure to capture its AWS Key and AWS Secret values and put this into your environment file. From there add the following policy to the user or its group.

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowSendingSMSMessages",
            "Effect": "Allow",
            "Action": [
                "sns:Publish",
                "sns:CheckIfPhoneNumberIsOptedOut"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

```

Here we set the ability to publish, check for opt-outs, and apply this across a wildcard resource instead of a specific topic as we will be sending notifications directly to phone numbers and not an SNS topic.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 88.6% 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 ~114 days

Recently: every ~183 days

Total

8

Last Release

1306d ago

Major Versions

0.2.0 → v1.0.02020-08-25

v1.4.0 → v2.0.12022-10-14

PHP version history (2 changes)v1.0.0PHP ^7.1.8

v2.0.1PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ab1b88ecc345016d46cddbcda5cfb04ae70f7a7f2509e6aaa75bdb7b9cc205c?d=identicon)[ferdous](/maintainers/ferdous)

---

Top Contributors

[![ferdousulhaque](https://avatars.githubusercontent.com/u/36291549?v=4)](https://github.com/ferdousulhaque "ferdousulhaque (31 commits)")[![alex-ng-wesoft](https://avatars.githubusercontent.com/u/40166654?v=4)](https://github.com/alex-ng-wesoft "alex-ng-wesoft (3 commits)")[![devstar0209](https://avatars.githubusercontent.com/u/56650395?v=4)](https://github.com/devstar0209 "devstar0209 (1 commits)")

---

Tags

hacktoberfestlaravellaravel-packagephplaravelotpemailsmsresendretrysecurity-codeotp-validation

### Embed Badge

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

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

###  Alternatives

[ellaisys/aws-cognito

AWS Cognito package that allows Auth and other related features using the AWS SDK for PHP

120220.7k1](/packages/ellaisys-aws-cognito)[juanparati/brevosuite

Complete Brevo integration with Laravel

1010.8k](/packages/juanparati-brevosuite)[djunehor/laravel-sms

Send SMS from your laravel application

385.3k1](/packages/djunehor-laravel-sms)[martian/spammailchecker

A laravel package that protect users from entering non-existing/spam email addresses.

422.0k](/packages/martian-spammailchecker)

PHPackages © 2026

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