putheakhem/laravel-otp
Composer 安装命令:
composer require putheakhem/laravel-otp
包简介
A simple OTP generator for Laravel
README 文档
README
A Laravel package for generating, validating, and managing One-Time Passwords (OTP) with security features.
📌 Features
- ✅ Rate-limited OTP generation
- ✅ Configurable expiration times
- ✅ Invalidate OTP after first use
- ✅ Lock OTP to user session
- ✅ Invalidate OTP after too many failed attempts
- ✅ View detailed error messages
- ✅ Customizable mail template
- ✅ Auditable logs for security
🔧 Installation
1️⃣ Install via Composer
composer require putheakhem/otp
2️⃣ Publish Configuration & Migrations
php artisan vendor:publish --provider="PutheaKhem\Otp\Providers\OtpServiceProvider"
php artisan migrate
This will create:
- A config file at
config/otp.php - A database table
otps
3 Configuration
Modify config/otp.php to adjust settings:
return [ 'length' => 6, // OTP length 'expires_in' => 300, // OTP expiration time in seconds (5 minutes) 'max_attempts' => 5, // Maximum failed attempts before invalidation 'lock_to_session' => true, // OTP tied to user session 'mail_template' => 'otp::emails.otp', // Email template for OTP 'logging_enabled' => true, // Enable OTP logging ];
🔥 Usage
Generate an OTP
use PutheaKhem\Otp\Facades\Otp; $otp = Otp::generate('user@example.com'); dd($otp);
📌 Output Example:
PutheaKhem\Otp\Models\Otp {#123 id: 1, identifier: "user@example.com", otp: "123456", used: false, attempts: 0, expires_at: "2025-02-10 12:00:00" }
Validate an OTP
$response = Otp::validate('user@example.com', '123456'); dd($response);
📌 Expected Output: ✅ Success
{
"status": true,
"message": "OTP verified successfully."
}
❌ Failure (Invalid OTP)
{
"status": false,
"message": "Invalid OTP."
}
❌ Failure (Expired OTP)
{
"status": false,
"message": "OTP expired or invalid."
}
📩 Email Customization
Customize the email template at:
resources/views/vendor/otp/emails/otp.blade.php
Example:
<!DOCTYPE html> <html> <head> <title>OTP Verification</title> </head> <body> <p>Your OTP is: <strong>{{ $otp }}</strong></p> <p>This OTP is valid for {{ config('otp.expires_in') / 60 }} minutes.</p> </body> </html>
🔬 Testing
Run All Tests
php artisan test
📌 Expected Output:
✔ can generate OTP
✔ can validate OTP
✔ OTP invalid after expiry
✔ OTP fails after too many attempts
✔ OTP logs events
✔ Emails are sent correctly
✔ OTP is locked to session
📢 Contributing
- Fork the repository
- Clone the repo:
git clone https://github.com/putheakhem/otp.git
- Create a new branch:
git checkout -b feature-branch
- Commit changes & push:
git commit -m "Added new feature" git push origin feature-branch - Submit a Pull Request 🚀
🏆 Credits
Developed by Puthea Khem.
Special thanks to the Laravel community! 🎉
📜 License
This package is open-source and licensed under the MIT License.
putheakhem/laravel-otp 适用场景与选型建议
putheakhem/laravel-otp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「otp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 putheakhem/laravel-otp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 putheakhem/laravel-otp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 putheakhem/laravel-otp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
OTP generating package
OTP generating package
Alfabank REST API integration
Laravel package for Beem API integration - SMS, Airtime, OTP, Payment Checkout, Collections, Contacts, Moja, and International SMS services
Create and verify One Time Passwords based on Time and HMAC. May be used in 2FA (Two Factor Authentication), MFA (Multi factor Authentication), 2SA (Two Step Authentication) and MSA (Multi Step Authentication).
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-13