blamodex/laravel-otp
Composer 安装命令:
composer require blamodex/laravel-otp
包简介
A simple, Laravel-ready one-time password (OTP) package for rapid prototyping and lightweight use cases.
README 文档
README
A lightweight Laravel package to add one-time password (OTP) capabilities to any Eloquent model using polymorphic relationships.
Table of Contents
🚀 Features
- Attach OTP functionality to any model using a trait
- Polymorphic support for multiple model types
- Configurable alphabet, length, expiry, and hash algorithm
- Secure hashing via
password_hashandpassword_verify - Auto-expiration and one-time use enforcement
- Clean architecture: trait, model, service, generator
📦 Installation
Install the package with Composer:
composer require blamodex/laravel-otp
Publish the config file:
php artisan vendor:publish --tag=blamodex-otp-config
Run the migrations:
php artisan migrate
⚙️ Configuration
Configuration lives in config/otp.php:
return [ /* PASSWORD ALGORITHM, SEE https://www.php.net/manual/en/function.password-hash.php FOR MORE INFO */ 'algorithm' => PASSWORD_BCRYPT, /* PASSWORD ALPHABET */ //NUMBERS ONLY ALPHABET 'alphabet' => '0123456789', //"WORD SAFE" ALPHABET //'alphabet' => '256789BCDFGHJKMNPQRSTVXW', //ALPHANUM ALPHABET //'alphabet' => '0123456789ABCDEFGHIJKLMNOPQRSTUV'; /* PASSWORD LENGTH */ 'length' => 6, /* PASSWORD EXPIRY */ 'expiry' => 600 ];
🧩 Usage
1. Implement the interface and use the trait
use Blamodex\Otp\Traits\OneTimePasswordable; use Blamodex\Otp\Contracts\OneTimePasswordableInterface; class User extends Model implements OneTimePasswordableInterface { use OneTimePasswordable; }
2. Generate an OTP
$user = User::find(1); $otp = $user->generateOtp(); // returns raw password
3. Verify an OTP
if ($user->verifyOtp('123456')) { // Success } else { // Failure }
🧪 Testing
This package uses Orchestra Testbench and PHPUnit.
Run tests:
composer test
Check code style:
composer lint
Check code style and fix:
composer lint:fix
Check coverage (with Xdebug):
composer test:coverage
📁 Project Structure
src/
├── Models/
│ └── OneTimePassword.php
├── Data/
│ └── OtpData.php
├── Services/
│ ├── OtpGenerator.php
│ └── OtpService.php
├── Traits/
│ └── OneTimePasswordable.php
├── Contracts/
│ └── OneTimePasswordableInterface.php
├── config/
│ └── otp.php
└── database/
└── migrations/
└── 202x_xx_xx_create_one_time_passwords_table.php
tests/
├── Unit/
├── Fixtures/
└── TestCase.php
🤝 Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
📝 Changelog
Please see CHANGELOG.md for recent changes.
📄 License
MIT © Blamodex
For more information, see the LICENSE file.
🔗 Links
blamodex/laravel-otp 适用场景与选型建议
blamodex/laravel-otp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 171 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「Authentication」 「laravel」 「otp」 「verification」 「one-time-password」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blamodex/laravel-otp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blamodex/laravel-otp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blamodex/laravel-otp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
Provide a way to secure accesses to all routes of an symfony application.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
It's a barebone security class written on PHP
Email Toolkit Plugin for CakePHP
统计信息
- 总下载量: 171
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-29