putheakhem/laravel-otp 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

putheakhem/laravel-otp

Composer 安装命令:

composer require putheakhem/laravel-otp

包简介

A simple OTP generator for Laravel

README 文档

README

Tests

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

  1. Fork the repository
  2. Clone the repo:
    git clone https://github.com/putheakhem/otp.git
  3. Create a new branch:
    git checkout -b feature-branch
  4. Commit changes & push:
    git commit -m "Added new feature"
    git push origin feature-branch
  5. 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 putheakhem/laravel-otp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-13