PHPackages                             adeshsuryan/laravel-otp-login - 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. adeshsuryan/laravel-otp-login

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

adeshsuryan/laravel-otp-login
=============================

Adds OTP login step to Laravel's built-in authentication system

5.13(6y ago)143MITPHP

Since Oct 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/adeshsuryan/laravel-otp-login)[ Packagist](https://packagist.org/packages/adeshsuryan/laravel-otp-login)[ RSS](/packages/adeshsuryan-laravel-otp-login/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (23)Used By (0)

Laravel OTP Login Package
=========================

[](#laravel-otp-login-package)

This package provides an One Time Password check step after successful login using the default authentication mechanism. The package stores all requested OTP and it's validation statuses in `one_time_passwords` and `one_time_password_logs` tables.

It uses the middleware included in this package to check if the user has passed the OTP check or not regarding the current authentication status.

Credits
-------

[](#credits)

This package is based on the idea of [tpaksu/laravel-otp-login](https://github.com/tpaksu/laravel-otp-login) package. The Rest API with controller strategy is developed by me.

Requirements
------------

[](#requirements)

- [Composer](https://getcomposer.org/)
- [Laravel](http://laravel.com/)

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

[](#installation)

You can install this package on an existing Laravel project with using composer:

```
 $ composer require adeshsuryan/laravel-otp-login
```

Then, register the OTP Login ServiceProvider editing **config/app.php** file and adding to providers array:

```
  adeshsuryan\LaravelOTPLogin\OTPServiceProvider::class,
```

Note: use the following for Laravel &lt;5.1 versions:

```
 'adeshsuryan\LaravelOTPLogin\OTPServiceProvider',
```

Publish files with:

```
 $ php artisan vendor:publish --provider="adeshsuryan\LaravelOTPLogin\OTPServiceProvider"
```

or by using only `php artisan vendor:publish` and select the `adeshsuryan\LaravelOTPLogin\OTPServiceProvider` from the outputted list.

Apply the migrations for the `OneTimePassword` and `OneTimePasswordLogs` tables:

```
 $ php artisan migrate
```

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

[](#configuration)

This package publishes an `otp.php` file inside your applications's `config` folder which contains the settings for this package. Most of the variables are bound to environment variables, but you are free to directly edit this file, or add the configuration keys to the `.env` file.

This line shows if the service is enabled or not:

```
'otp_service_enabled' => true,
```

On this line, you can configure the default SMS service the system will use to send the OTP SMS'es:

```
'otp_default_service' => env("OTP_SERVICE", "nexmo"),
```

The services predefined in this package are `Nexmo`, `Twilio` and `BioTekno` for now, but it's very easy to add your custom service to this package. It'll be explained in detail in the [Services](#services) section of this documentation.

```
'services' => [
    'biotekno' => [
        "class" => \adeshsuryan\LaravelOTPLogin\Services\BioTekno::class,
        "username" => env('OTP_USERNAME', null),
        "password" => env('OTP_PASSWORD', null),
        "transmission_id" => env('OTP_TRANSMISSION_ID', null)
    ],
    'nexmo' => [
        'class' => \adeshsuryan\LaravelOTPLogin\Services\Nexmo::class,
        'api_key' => env("OTP_API_KEY", null),
        'api_secret' => env('OTP_API_SECRET', null),
        'from' => env('OTP_FROM', null)
    ],
    'twilio' => [
        'class' => \adeshsuryan\LaravelOTPLogin\Services\Twilio::class,
        'account_sid' => env("OTP_ACCOUNT_SID", null),
        'auth_token' => env("OTP_AUTH_TOKEN", null),
        'from' => env("OTP_FROM", null)
    ],
     'msg91' => [
         'class' => \adeshsuryan\LaravelOTPLogin\Services\Msg91::class,
         'api_key' => env("OTP_API_KEY", null),
         'sender' => env('OTP_API_SENDER',null),
         'route' => env('OTP_ROUTE', '4'),
          'country' => env('OTP_COUNTRY', '0'),
     ]
],
```

This is very important. The service expects you to have a phone field in your `users` table or a related table to send the SMS to the user. If your user's phone number is in the `users` table, you can write the field name directly to this setting.

```
'user_phone_field' => 'phone',
```

Otherwise, if it's in a table like `user_phones` linked to your `users` table, you can use the linked setting like this:

```
'user_phone_field' => 'user_phone.phone',
```

This line shows the length of the generated one time password's reference number. See `otp_digit_length` setting description for limitations. It's not currently used in SMS but it's generated and saved to database. In later versions, I plan to implement it to the services.

```
'otp_reference_number_length' => 6,
```

This defines the OTP validity timeout in seconds, currently set as 3 months.

```
'otp_timeout' => 7890000,
```

This line shows the length of the generated one time password. It should be below 10 because of PHP's integer limit which is 232 (2,147,483,647) on 32-bit machines. It'll be more configurable in the later versions, but I don't think it'll be needed more than 10 digits for UX reasons.

```
'otp_digit_length' => 6,
```

Views
-----

[](#views)

This package publishes one view named `otpvalidate.blade.php` to `resources/views/vendor/laravel-otp-login` folder, which contains the OTP validation screen. The strings used in this view are fetched from the language files also published in this package, so if you are trying to change the strings inside this view, you can change it inside the language file.

Translations
------------

[](#translations)

This package publishes the translations to `resources/lang/vendor/laravel-otp-login` folder, Turkish and English languages are published by this package as `php` files, and you can translate it into more languages by using the English language file as a template. Here's the content of the English file as an example:

```
