Download the PHP package salehhashemi/laravel-otp-manager without Composer

On this page you can find all versions of the php package salehhashemi/laravel-otp-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-otp-manager

# Laravel OTP Manager [![Latest Version on Packagist](https://img.shields.io/packagist/v/salehhashemi/laravel-otp-manager.svg?style=flat-square)](https://packagist.org/packages/salehhashemi/laravel-otp-manager) [![Total Downloads](https://img.shields.io/packagist/dt/salehhashemi/laravel-otp-manager.svg?style=flat-square)](https://packagist.org/packages/salehhashemi/laravel-otp-manager) [![GitHub Actions](https://img.shields.io/github/actions/workflow/status/salehhashemi1992/laravel-otp-manager/run-tests.yml?branch=main&label=tests)](https://github.com/salehhashemi1992/laravel-otp-manager/actions/workflows/run-tests.yml) [![GitHub Actions](https://img.shields.io/github/actions/workflow/status/salehhashemi1992/laravel-otp-manager/static-analysis.yml?branch=main&label=static-analysis)](https://github.com/salehhashemi1992/laravel-otp-manager/actions/workflows/static-analysis.yml) [![codecov](https://codecov.io/gh/salehhashemi1992/laravel-otp-manager/graph/badge.svg?token=EJB78FT27M)](https://codecov.io/gh/salehhashemi1992/laravel-otp-manager) [![PHPStan](https://img.shields.io/badge/PHPStan-level%208-brightgreen.svg?style=flat)](https://phpstan.org/) ![Header Image](./assets/header.png)

The OtpManager class is responsible for sending and verifying one-time passwords (OTPs). It provides a comprehensive set of methods to generate, send, verify, and manage OTPs. It also integrates with Laravel cache system to throttle OTP sending and provides a layer of security by tracking OTP requests.

Features

Requirements

Version L9 L10 L11
1.5 :white_check_mark: :white_check_mark: :white_check_mark:

Installation

To install the package, you can run the following command:

Usage

Sending OTP

Resending OTP

The sendAndRetryCheck method will throw a ValidationException if you try to resend the OTP before the waiting time expires.

Verifying OTP

Deleting Verification Code

Handling and Listening to the OtpPrepared Event

The OtpManager package emits an OtpPrepared event whenever a new OTP is generated. You can listen to this event and execute custom logic, such as sending the OTP via SMS or email.

Here's how to set up an event listener:

Step 1: Register the Event and Listener

First, you need to register the OtpPrepared event and its corresponding listener. Open your EventServiceProvider file, usually located at app/Providers/EventServiceProvider.php, and add the event and listener to the $listen array.

Step 2: Create the Listener

If the listener does not exist, you can generate it using the following Artisan command:

Step 3: Implement the Listener

Now open the generated SendOtpNotification listener file, typically located at app/Listeners/. You'll see a handle method, where you can add your custom logic for sending the OTP.

Here's a sample implementation:

Step 4: Test the Event Listener

Once you've set up the listener, generate a new OTP through the OtpManager package to make sure the OtpPrepared event is being caught and the corresponding listener logic is being executed.

That's it! You've successfully set up an event listener for the OtpPrepared event in the OtpManager package.

Using Enums for OTP Types

You can take advantage of enums to define your OTP types. Enums provide a more expressive way to manage different categories of OTPs.

How to Define an OTP Enum

Usage

After defining your enum, you can use it just like any other OTP type:

Configuration

To publish the config file, run the following command:

To publish the language files, run:

After publishing, make sure to clear the config cache to apply your changes:

Then, you can adjust the waiting_time, code_min, and code_max in the config/otp.php

Middleware Protection

The OtpManager package includes built-in middleware (OtpRateLimiter) to protect your application routes from excessive OTP requests. This helps prevent potential abuse.

To apply the middleware:

Register the middleware: Add \Salehhashemi\OtpManager\Middleware\OtpRateLimiter::class to the middlewareAliases array in your app\Http\Kernel.php file.

Assign the middleware to routes: You can apply it to specific routes or route groups where you want to implement rate limiting.

Example:

Custom Mobile Number Validation

The package comes with a default mobile number validator, but you can easily use your own.

Here's how you can do it:

  1. Create a Custom Validator Class First, create a class that implements MobileValidatorInterface. This interface expects you to define a validate method.

  2. Update Configuration Next, open your OTP configuration file and update the mobile_validation_class option to use your custom validator class:

Exceptions

Docker Setup

This project uses Docker for local development and testing. Make sure you have Docker and Docker Compose installed on your system before proceeding.

Build the Docker images

Start the services

To access the PHP container, you can use:

Testing

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

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


All versions of laravel-otp-manager with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel/framework Version ^9.0|^10.0|^11.0
salehhashemi/laravel-configurable-cache Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package salehhashemi/laravel-otp-manager contains the following files

Loading the files please wait ....