prasanth-j/otpify 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

prasanth-j/otpify

最新稳定版本:v1.0.3

Composer 安装命令:

composer require prasanth-j/otpify

包简介

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

README 文档

README

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('john@example.com', 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('john@example.com', '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.

统计信息

  • 总下载量: 39
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固