Skip to content

A super simple package to generate OTP and Validate OTP

License

Notifications You must be signed in to change notification settings

SignatureTech/laravel-otp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel

LaravelOtp : generate OTP and Validate OTP


Table of contents

Introduction

LaravelOtp is a Laravel package, designed to generate OTP and Validate OTP using simple steps. This packages will show all OTP history.

Todo

  • Generate OTP
  • Verify OTP
  • OTP Lists
  • Test Cases

Features

  • Generate OTP
  • Verify OTP
  • Get the User OTP List
  • Generate custom lenth, expiry and formate OTP

Installation & Configuration

You can install this package via composer using:

composer require signaturetech/laravel-otp

Now add the use SignatureTech\LaravelOtp\Traits\Otpable trait to your model.

use SignatureTech\LaravelOtp\Traits\Otpable;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, Otpable;
}

Generate OTP

Please use below code to generate otp:

  1. Get User Details
use App\Models\User;

$user = User::first();
  1. Create Otp Insatance
use SignatureTech\LaravelOtp\Otp;


$otp = Otp::for($user->email)->generate();

Note: You can use email/mobile/phone number to generate otp Just pass the detail using for method.

Note: You can use more method to setting otp all methods described in methods section.

  1. Attach Otp with user
$userOtp = $user->createOtp($otp);

$otp = $user->otp;

Verify OTP

You can verifu otp by useing below code:

  1. Get the use details
use App\Models\User;

$user = User::first();
  1. Get Otp Insatance
use SignatureTech\LaravelOtp\Otp;


$otp = Otp::for($user->email)->getOtp();
  1. Verify Otp
try {
    $user->verifyOtp($otp, $request->get('otp'));
} catch (OtpInvalidException $e) {
    return $e->getMessage;
} catch (OtpExpiredException $e) {
    return $e->getMessage;
}

License

About

A super simple package to generate OTP and Validate OTP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages