fisal/laravel-otp
最新稳定版本:v1.0.3
Composer 安装命令:
composer require fisal/laravel-otp
包简介
A simple package to generate and validate OTPs (internal fork with improvements)
README 文档
README
A lightweight Laravel package to generate and validate one-time passwords (OTPs).
This is a maintained fork intended for real projects: it adds OTP type binding (e.g. login, 2fa) and an attempts limit.
Installation
composer require fisal/laravel-otp:^1.0
Configuration (optional)
Publish config (optional):
php artisan vendor:publish --tag=otp-config
Then you can control max attempts via:
config/otp.php- or env:
OTP_MAX_ATTEMPTS=5
Usage
Generate OTP
use Otp; // tokenType: numeric | alpha_numeric // otpType: purpose binding (login | 2fa | reset_password | ...) $result = Otp::generate( identifier: '201001234567', tokenType: 'numeric', length: 6, validity: 5, otpType: 'login' ); $token = $result->token;
Validate OTP (consumes on success)
$result = Otp::validate( identifier: '201001234567', token: '123456', otpType: 'login' ); if ($result->status) { // valid } else { // invalid / expired // optional: $result->remaining_attempts }
Boolean check (does NOT consume)
$isValid = Otp::isValid('201001234567', '123456', 'login');
Artisan
Clean invalid and expired OTPs:
php artisan otp:clean
License
MIT
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-12