承接 rahmatwaisi/otp-auth 相关项目开发

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

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

rahmatwaisi/otp-auth

最新稳定版本:v1.0.2

Composer 安装命令:

composer require rahmatwaisi/otp-auth

包简介

Easily Generate and Verify an OTP using laravel cache

README 文档

README

rahmatwaisi-otp-auth

Latest Version on Packagist Total Downloads Software License Build Status

Installation

You can install the package with Composer.

composer require rahmatwaisi/otp-auth

Usage

Creating an OTP

All you need is to use the OtpGenerator facade as below:

use RahmatWaisi\OtpAuth\Facades\OtpGenerator;
use RahmatWaisi\OtpAuth\Core\OtpType;
.
.
// To Create a new OTP using a key like User::$id or User::$email, etc.
$otp = OtpGenerator::create('key') // output: 234234

Another more customizeable way is to determine prefix, key, ttl, length, type, etc.

$user = User::query()->inRandomOrder()->first();

$otp = OtpGenerator::createFrom('smth',  $user->id) // output: 234234, a 6-digit integer

$otp = OtpGenerator::createFrom('smth',  $user->email, OtpType::NUMBER) // output: 234234, a 6-digit integer

$otp = OtpGenerator::createFrom('smth',  $user->username, OtpType::STRING) // output: "aBcDeF", a 6-char string

$otp = OtpGenerator::createFrom('smth',  $user->custom_key, OtpType::NUMBER, 12, now()->addDay()) // output: 123321234234, a 12-digit integer

$otp = OtpGenerator::createFrom('smth',  $user->whatever, OtpType::STRING, 8, now()->addDay()) // output: "aBcdEfgH", an 8-char string

All codes above are using the publishable configs in the package which are located in configs/otp.php

Another way that you can customize any configs in the runtime is:

$otp = OtpGenerator::builder()
    ->withPrefix('dummy_prefix')
    ->withKey('my_custom_key')
    ->withType(OtpType::NUMBER)
    ->withTtl(now()->addMinutes(2))
    ->withLength(8)
    ->build();

// Output: 12345678, an 8-digit integer

Resolving, Validating, Removing an OTP

All you need is to use the OtpGenerator facade as below:

use RahmatWaisi\OtpAuth\Facades\OtpGenerator;
use RahmatWaisi\OtpAuth\Core\OtpType;
.
.
// To Remove, Forget or Resolve an OTP using a key like User::$id or User::$email, etc. Do like this:

// Forgets the OTP just using the key
OtpGenerator::forget($user->id);

// Checks wether an incoming OTP from request exists or not?
OtpGenerator::verify($user->id, request()->get('otp'));
OtpGenerator::verifyUsing('custom_prefix', $user->id, request()->get('otp'));

// Removes an OTP using both key and its value
OtpGenerator::remove($key, 'aBcDeFgH');

// Gets an OTP just using the key
OtpGenerator::get($key);
OtpGenerator::get($user->username);

Another more customizeable way is to determine prefix, key, ttl, length, type, etc.

$user = User::query()->inRandomOrder()->first();

// Get an OTP just using the key and default configs
OtpGenerator::resolver()->withDefaultSettings()->withKey($user->id)->resolve();

// Forgets an OTP just using the key and default configs
OtpGenerator::resolver()->withDefaultSettings()->withKey($user->id)->forget();

// Checks for existence of an OTP just using the key and default configs
OtpGenerator::resolver()->withDefaultSettings()->withKey($user->id)->exists(request()->get('otp'));

// Get an OTP just using the key and default prefix
OtpGenerator::resolver()->withDefaultPrefix()->withKey($user->id)->resolve();

//  Checks for existence of an OTP just using the key and default perfix
OtpGenerator::resolver()->withDefaultPrefix()->withKey($user->id)->exists(request()->get('otp'));

All codes above are using the publishable configs in the package which are located in configs/otp.php

Another way that you can customize any configs in the runtime is:

// Get an OTP just using the key and custom prefix
$otp = OtpGenerator::resolver()
    ->withPrefix('smth')
    ->withKey($user->id)
    ->resolve();

Conclusion

By using this package you can easily creat and validate any form with any length of OTPs.

Contribution

Feel free to suggest improvements, I'll appreciate any contribution from anyone. Thank you.

Made with 💙 In a late late night.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固