定制 danielrobert/otp-generator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

danielrobert/otp-generator

最新稳定版本:v1.08

Composer 安装命令:

composer require danielrobert/otp-generator

包简介

A Laravel Package for Generating and Validating Otp using database

README 文档

README

Latest Version on Packagist Quality Score Code Quality Github Workflow Status

Licence

Installation

You may use the Composer package manager to install Otp Generator into your Laravel project:

composer require danielrobert/otp-generator

After installing the otp-generator, you need to publish its configuration and migration files. The migration files will be copied to your application's database/migrations directory, but they are not run automatically. You must run the migrate command yourself to create the necessary tables:

php artisan vendor:publish --provider="DanielRobert\Otp\OtpGeneratorServiceProvider" --tag=otp-migrations
php artisan vendor:publish --provider="DanielRobert\Otp\OtpGeneratorServiceProvider" --tag=otp-config
php artisan migrate

Configuration

After publishing Otp Generator's configs, its primary configuration file will be located at config/otp-generator.php. This configuration file allows you to configure your otps. Each configuration option includes a description of its purpose, so be sure to thoroughly explore this file.

Data Pruning

Data Pruning Without pruning, the otps table can accumulate records very quickly. To mitigate this, you can schedule the otp:prune Artisan command to run daily:

$schedule->command('otp:prune')->daily();

By default, all expired entries or entries older than 30 minutes as configured in the config/otp-generator.php will be pruned. You may use the minutes option when calling the command to determine how long to retain data. For example, the following command will delete all records created over 60 minutes ago:

$schedule->command('otp:prune --minutes=60')->daily();

Usage

use DanielRobert\Otp\Otp;
.
.
$otp =  Otp::generate($identifier);
.
$verify = Otp::validate($identifier, $otp->token);

// example response
{
  "status": true
  "message": "Otp is valid"
}

// to get an expiredAt time
$expires = Otp::expiredAt($identifier);

// example response 
+"status": true
+"expired_at": Illuminate\Support\Carbon @1611895244^ {
  ....
  #dumpLocale: null
  date: 2021-01-29 04:40:44.0 UTC (+00:00)
}

Advance Usage

In addition to configuring otps from the otp-generator.php config file you can also configure it directly

use DanielRobert\Otp\Otp;
.
.
$otp =  Otp::setValidity(30)  // otp validity time in mins
      ->setLength(4)  // Lenght of the generated otp
      ->setMaximumOtpsAllowed(10) // Number of times allowed to regenerate otps
      ->setOnlyDigits(false)  // generated otp contains mixed characters ex:ad2312
      ->setUseSameToken(true) // if you re-generate Otp, you will get same token
      ->generate($identifier);
.
$verify = Otp::setAllowedAttempts(10) // number of times they can allow to attempt with wrong token
    ->validate($identifier, $otp->token);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-18