Otpify is a Laravel package that provides a simple and elegant way to generate and validate one time passwords.

Overview

Laravel Otpify 🔑

Build Status Total Downloads Latest Version on Packagist License: MIT

Introduction

Otpify is a Laravel package that provides a simple and elegant way to generate and validate one time passwords.

Installation

You can install the package via composer:

composer require prasanth-j/otpify

You can run the migrations with:

php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="otpify-config"

This is the contents of the published config file:

return [
    /**
     * The length of token.
     */
    'digits'    => 6,

    /**
     * The expiry time of token in minutes.
     */
    'validity'  => 15
];

Optionally, you can publish the migrations using

php artisan vendor:publish --tag="otpify-migrations"

Usage

1. Generate OTP

use PrasanthJ\Otpify\Facades\Otpify;

Otpify::generate(string $identifier, int $userId, string $otpType, int $digits, int $validity);
  • $identifier: The identity (email or mobile) that will be tied to the OTP.
  • $userId (optional | default = null): The user id from user table.
  • $otpType (optional | default = null): The category of the OTP, like login, verification, etc.
  • $digits (optional | default = 6): The amount of digits to be generated, should be 4 to 8.
  • $validity (optional | default = 15): The validity period of the OTP in minutes.

Example

use PrasanthJ\Otpify\Facades\Otpify;

$otp = Otpify::generate('[email protected]', 2, 'verification', 6, 10);

This will generate a six digit OTP that will be valid for 10 minutes and the success response will be:

{
  "status": "success",
  "token": "535923",
  "message": "OTP genetated successfully"
}

2. Validate OTP

use PrasanthJ\Otpify\Facades\Otpify;

Otpify::validate(string $identifier, string $token, string $otpType);
  • $identifier: The identity (email or mobile) that will be tied to the OTP.
  • $token: The token tied to the identity.
  • $otpType (optional | default = null): The category of the OTP, like login, verification, etc.

Example

use PrasanthJ\Otpify\Facades\Otpify;

$otp = Otpify::generate('[email protected]', '535923', 'verification');

Responses

On Success

{
  "status": "success",
  "message": "OTP is valid"
}

Does not exist

{
  "status": "error",
  "message": "OTP does not exist"
}

On Error

{
  "status": "warning",
  "message": "OTP invalid"
}

Expired

{
  "status": "error",
  "message": "OTP Expired"
}

Already Verified

{
  "status": "info",
  "message": "OTP already verified"
}

Delete verified tokens

You can delete verified tokens by running the following artisan command:

php artisan otpify:clean

You can also add this artisan command to app/Console/Kernel.php to automatically clean on scheduled

protected function schedule(Schedule $schedule)
{
    $schedule->command('otpify:clean')->daily();
}

Contribution

If you find an issue with this package or you have any suggestions please help out.

License

The MIT License (MIT). Please see License File for more information.

You might also like...
A kernel designed to run one and only one application in a virtualized environment
A kernel designed to run one and only one application in a virtualized environment

nanos Nanos is a new kernel designed to run one and only one application in a virtualized environment. It has several constraints on it compared to a

One-to-one plugin for editing world chat messages.

WorldChat One-to-one plugin for editing world chat messages. Supports English and Turkish language To set a new world chat format /worldchat new "worl

Kalibrant - a package that provides a simple way to manage your models settings
Kalibrant - a package that provides a simple way to manage your models settings

Introduction For your laravel 9.x applications, Kalibrant is a package that provides a simple way to manage your models settings. It is a simple way t

An elegant package for integrate laravel with openwa
An elegant package for integrate laravel with openwa

Whatsapp Laravel An elegant package to integrate Laravel with Whatsapp automate Features Function Reference Send text Send contact Send media (doc, im

A simple way to generate files from stubs.

STUBBY A simple way to generate files from stubs. Usage For example we have a stub file that looks like this: ?php namespace {{ namespace }}; use A

A Laravel package that allows you to validate your config values and environment.
A Laravel package that allows you to validate your config values and environment.

Table of Contents Overview Installation Requirements Install the Package Publishing the Default Rulesets Usage Creating a Validation Ruleset Using the

🛂 Use this package to validate the identity card from your country using laravel validation rules.

Identity Card Checker Laravel Validation Rules Use this package to validate the identity card number from your country Installation You can install th

A simple Laravel package for generating download links with options such as expire time, IP restrictions, etc.

Generate download links in your Laravel applications This package allows you to generate download links for files. Once installed you can do stuff lik

This package provides a trait that will generate a unique uuid when saving any Eloquent model.

Generate slugs when saving Eloquent models This package provides a trait that will generate a unique uuid when saving any Eloquent model. $model = new

Releases(v1.0.3)
Owner
Prasanth Jayakumar
ɪɴ ᴀ ᴡᴏʀʟᴅ ғᴜʟʟ ᴏғ ғɪsʜ, ʙᴇ ᴀ sʜᴀʀᴋ🦈
Prasanth Jayakumar
Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Jameson Lopp 28 Dec 19, 2022
A Laravel package to manage versions of endpoints in an elegant way

API version control A Laravel package to manage versions of endpoints in an elegant way Two ways to manage the versions of your endpoints Option 1: Ve

Reindert 156 Dec 9, 2022
A laravel package to handle model specific additional meta fields in an elegant way.

Laravel Meta Fields A php package for laravel framework to handle model meta data in a elegant way. Installation Require the package using composer: c

Touhidur Rahman 26 Apr 5, 2022
Laravel package to generate and to validate a UUID according to the RFC 4122 standard. Only support for version 1, 3, 4 and 5 UUID are built-in.

Laravel Uuid Laravel package to generate and to validate a universally unique identifier (UUID) according to the RFC 4122 standard. Support for versio

Christoph Kempen 1.7k Dec 28, 2022
A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache.

Laravel OTP Introduction A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache. The ca

Lim Teck Wei 52 Sep 6, 2022
A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

Munaf Aqeel Mahdi 1.7k Jan 5, 2023
This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.

Laravel Verify New Email Laravel supports verifying email addresses out of the box. This package adds support for verifying new email addresses. When

Protone Media 300 Dec 30, 2022
MySecureVault is the most secure passwords, notes and files vault on the Internet.

MySecureVault MySecureVault is the most secure passwords, notes and files vault on the Internet. It has been developed with ultimate privacy and secur

MySecureVault 1 Jan 26, 2022
Prevent users from reusing recently used passwords

Laravel Password History Validation Prevent users from reusing recently used passwords. Installation You can install the package via composer: compose

Paul Edward 67 Oct 10, 2022
A simple laravel package to validate console commands arguments and options.

Command Validator A simple laravel package to validate console commands arguments and options. Installation Require/Install the package using composer

Touhidur Rahman 20 Jan 20, 2022