PHPackages                             cuongnd88/otp-auth - 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. cuongnd88/otp-auth

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

cuongnd88/otp-auth
==================

Laravel OTP Authentication (One Time Passwords)

1.3(4y ago)105282MITPHPPHP ^7.2.5

Since Jun 10Pushed 4y ago1 watchersCompare

[ Source](https://github.com/cuongdinhngo/otp-auth)[ Packagist](https://packagist.org/packages/cuongnd88/otp-auth)[ Docs](https://github.com/cuongnd88/otp-auth)[ RSS](/packages/cuongnd88-otp-auth/feed)WikiDiscussions master Synced 1mo ago

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

Laravel OTP AUTH
================

[](#laravel-otp-auth)

This package allows you to authenticate with one time password access (OTP).

Example Usage:

```
Route::get("/notify", function(){
    return App\Models\User::find(1)->notify(new App\Authentication\SendOtp('mail', 4, 10));
});

Route::get("/auth-otp/{otp}", function(){
    return App\Models\User::authByOtp(request()->otp, '84905.......');
});

Route::get("/check-otp/{otp}", function(){
    return App\Models\User::find(1)->checkOtp(request()->otp);
});
```

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Generate OTP](#generate-otp)
    - [Verify OTP](#verify-otp)
    - [Basic identification](#basic-identification)
    - [Demo](#demo)
- [Credits](#credits)

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

[](#installation)

1- Add the package to your dependencies.

```
$ composer require cuongdinhngo/otp-auth

```

2- Run the command:

```
php artisan auth:otp {ClassName}
```

Example:

```
php artisan auth:otp Authentication/SendOtp
```

*`SendOtp` class and `HasOtpAuth` trait are auto-generated at `app/Authentication` directory.*

*`CreateNotificationsTable` class is alseo auto-generated at `app/database/migrations`.*

3- Apply the migrations:

*It will create a table called `notifications` to store generated OTP information.*

```
$ php artisan migrate

```

Usage
-----

[](#usage)

### Generate OTP

[](#generate-otp)

You can generate OTP via email or SMS

```
Route::get("/notify", function(){
    return App\Models\User::find(1)->notify(new App\Authentication\SendOtp(['mail', 'nexmo']));
});
```

This package allows you to alter OTP length and lifetime

```
Route::get("/notify", function(){
	$length = 4;
	$liftime = 10; //minutes
    return App\Models\User::find(1)->notify(new App\Authentication\SendOtp(['mail', 'nexmo']), $length, $liftime);
});
```

**OTP default length**: The default length is `6`.

**OTP default lifetime**: The default lifetime is `1` minute.

There is the detail of auto-generate `SentOTP` class:

```
