承接 ichtrojan/laravel-otp 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ichtrojan/laravel-otp

最新稳定版本:v2.0.0

Composer 安装命令:

composer require ichtrojan/laravel-otp

包简介

A simple package to generate and validate OTPs

README 文档

README

Latest Stable Version Total Downloads License

Introduction 🖖

This is a simple package to generate and validate OTPs (One Time Passwords). This can be implemented mostly in Authentication.

Installation 💽

Install via composer

composer require ichtrojan/laravel-otp

Run Migrations

php artisan migrate

Usage 🧨

NOTE
Response are returned as objects. You can access its attributes with the arrow operator (->)

Generate OTP

<?php

use Ichtrojan\Otp\Otp;

(new Otp)->generate(string $identifier, string $type, int $length = 4, int $validity = 10);
  • $identifier: The identity that will be tied to the OTP.
  • $type: The type of token to be generated, supported types are numeric and alpha_numeric
  • $length (optional | default = 4): The length of token to be generated.
  • $validity (optional | default = 10): The validity period of the OTP in minutes.

Sample

<?php

use Ichtrojan\Otp\Otp;

(new Otp)->generate('michael@okoh.co.uk', 'numeric', 6, 15);

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

{
  "status": true,
  "token": "282581",
  "message": "OTP generated"
}

Validate OTP

<?php

use Ichtrojan\Otp\Otp;

(new Otp)->validate(string $identifier, string $token)
  • $identifier: The identity that is tied to the OTP.
  • $token: The token tied to the identity.

Sample

<?php

use Ichtrojan\Otp\Otp;

(new Otp)->validate('michael@okoh.co.uk', '282581');

Responses

On Success

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

Does not exist

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

Not Valid*

{
  "status": false,
  "message": "OTP is not valid"
}

Expired

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

Check The validity of an OTP

To verify the validity of an OTP without marking it as used, you can use the isValid method:

<?php
use Ichtrojan\Otp\Otp;

(new Otp)->isValid(string $identifier, string $token);

This will return a boolean value of the validity of the OTP.

Delete expired tokens

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

php artisan otp:clean

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

<?php

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

Contribution

If you find an issue with this package or you have any suggestion please help out. I am not perfect.

统计信息

  • 总下载量: 316.56k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 267
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 1

GitHub 信息

  • Stars: 267
  • Watchers: 8
  • Forks: 63
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-18