rahmatwaisi/otp-auth
Composer 安装命令:
composer require rahmatwaisi/otp-auth
包简介
Easily Generate and Verify an OTP using laravel cache
关键字:
README 文档
README
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.
rahmatwaisi/otp-auth 适用场景与选型建议
rahmatwaisi/otp-auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「auth」 「laravel」 「otp」 「laravel package」 「Laravel Auth」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rahmatwaisi/otp-auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rahmatwaisi/otp-auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rahmatwaisi/otp-auth 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Laravel Multiauth package
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
This package provides a flexible way to add Role-based Permissions to Laravel 6.x
Email Toolkit Plugin for CakePHP
Alfabank REST API integration
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-11