定制 signdeer/otpz 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

signdeer/otpz

Composer 安装命令:

composer require signdeer/otpz

包简介

First Factor One-Time Passwords for Laravel (Passwordless OTP Login)

README 文档

README

This fork is maintained by Signdeer, a secure, modern platform for e-signatures, approvals, and digital document workflows built for African teams and global standards.

First Factor One-Time Passwords for Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

This package provides secure first factor one-time passwords (OTPs) for Laravel applications. Users enter their email and receive a one-time code to sign in.

  • ✅ Rate-limited
  • ✅ Configurable expiration
  • ✅ Invalidated after first use
  • ✅ Locked to the user's session
  • ✅ Invalidated after too many failed attempts
  • ✅ Detailed error messages
  • ✅ Customizable mail template
  • ✅ Auditable logs

Starter Kits

Laravel + React Starter Kit

  1. New Applications

    Create a new Laravel project using the OTPz + React starter kit with the following command:

    laravel new --using benbjurstrom/otpz-react-starter-kit otpz-react
  2. Existing Applications:

    You can see a diff of all changes needed to integrate OTPz with the official Laravel + React Starter Kit here: https://github.com/laravel/react-starter-kit/compare/main...benbjurstrom:otpz-react-starter-kit:main

Laravel + Vue Starter Kit

  1. New Applications

    Create a new Laravel project using the OTPz + Vue starter kit with the following command:

    laravel new --using signdeer/otpz-vue-starter-kit otpz-vue
  2. Existing Applications:

    You can see a diff of all changes needed to integrate OTPz with the official Laravel + Vue Starter Kit here: https://github.com/laravel/vue-starter-kit/compare/main...benbjurstrom:otpz-vue-starter-kit:main

Laravel + Livewire Starter Kit

  1. New Applications

    Create a new Laravel project using the OTPz + Livewire starter kit with the following command:

    laravel new --using signdeer/otpz-livewire-starter-kit otpz-livewire
  2. Existing Applications:

    You can see a diff of all changes needed to integrate OTPz with the official Laravel + Livewire Starter Kit here: https://github.com/laravel/livewire-starter-kit/compare/main...benbjurstrom:otpz-livewire-starter-kit:main

Installation

1. Install the package via composer:

composer require signdeer/otpz

2. Publish and run the migrations

php artisan vendor:publish --tag="otpz-migrations"
php artisan migrate

3. Add the package's interface and trait to your Authenticatable model

// app/Models/User.php
namespace App\Models;

//...
use BenBjurstrom\Otpz\Models\Concerns\HasOtps;
use BenBjurstrom\Otpz\Models\Concerns\Otpable;

class User extends Authenticatable implements Otpable
{
    use HasFactory, Notifiable, HasOtps;
    
    // ...
}

4. (Optional) Add the following routes

Not needed with Laravel 12 starter kits. Instead, see the Usage section for examples.

// routes/auth.php
use BenBjurstrom\Otpz\Http\Controllers\GetOtpController;
use BenBjurstrom\Otpz\Http\Controllers\PostOtpController;
//...
Route::get('otpz/{id}', GetOtpController::class)
    ->name('otpz.show')->middleware('guest');

Route::post('otpz/{id}', PostOtpController::class)
    ->name('otpz.post')->middleware('guest');

5. (Optional) Publish the views for custom styling

php artisan vendor:publish --tag="otpz-views"

This package publishes the following views:

resources/
└── views/
    └── vendor/
        └── otpz/
            ├── otp.blade.php               (for entering the OTP)
            ├── components/template.blade.php
            └── mail/
                ├── notification.blade.php  (standard template)
                └── otpz.blade.php          (custom template)

6. (Optional) Publish the config file

php artisan vendor:publish --tag="otpz-config"

This is the contents of the published config file:

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Expiration and Throttling
    |--------------------------------------------------------------------------
    |
    | These settings control the security aspects of the generated codes,
    | including their expiration time and the throttling mechanism to prevent
    | abuse.
    |
    */

    'expiration' => 5, // Minutes

    'limits' => [
        ['limit' => 1, 'minutes' => 1],
        ['limit' => 3, 'minutes' => 5],
        ['limit' => 5, 'minutes' => 30],
    ],

    /*
    |--------------------------------------------------------------------------
    | Model Configuration
    |--------------------------------------------------------------------------
    |
    | This setting determines the model used by Otpz to store and retrieve
    | one-time passwords. By default, it uses the 'App\Models\User' model.
    |
    */

    'models' => [
        'authenticatable' => App\Models\User::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Mailable Configuration
    |--------------------------------------------------------------------------
    |
    | This setting determines the Mailable class used by Otpz to send emails.
    | Change this to your own Mailable class if you want to customize the email
    | sending behavior.
    |
    */

    'mailable' => BenBjurstrom\Otpz\Mail\OtpzMail::class,

    /*
    |--------------------------------------------------------------------------
    | Template Configuration
    |--------------------------------------------------------------------------
    |
    | This setting determines the email template used by Otpz to send emails.
    | Switch to 'otpz::mail.notification' if you prefer to use the default
    | Laravel notification template.
    |
    */

    'template' => 'otpz::mail.otpz',
    // 'template' => 'otpz::mail.notification',
    
    /*
    |--------------------------------------------------------------------------
    | User Resolver
    |--------------------------------------------------------------------------
    |
    | Defines the class responsible for finding or creating users by email address.
    | The default implementation will create a new user when an email doesn't exist.
    | Replace with your own implementation for custom user resolution logic.
    |
    */

    'user_resolver' => BenBjurstrom\Otpz\Actions\GetUserFromEmail::class,
];

Usage With Breeze

Laravel Breeze Livewire Example

  1. Replace the Breeze provided App\Livewire\Forms\LoginForm::authenticate method with a sendEmail method that runs the SendOtp action. Also be sure to remove password from the LoginForm's properties.
    // app/Livewire/Forms/LoginForm.php
    
    use BenBjurstrom\Otpz\Actions\SendOtp;
    use BenBjurstrom\Otpz\Exceptions\OtpThrottleException;
    use BenBjurstrom\Otpz\Models\Otp;
    //...
    
    #[Validate('required|string|email')]
    public string $email = '';

    #[Validate('boolean')]
    public bool $remember = false;
    //...
    
    public function sendEmail(): Otp
    {
        $this->validate();

        $this->ensureIsNotRateLimited();
        RateLimiter::hit($this->throttleKey(), 300);

        try {
            $otp = (new SendOtp)->handle($this->email, $this->remember);
        } catch (OtpThrottleException $e) {
            throw ValidationException::withMessages([
                'form.email' => $e->getMessage(),
            ]);
        }

        RateLimiter::clear($this->throttleKey());
        
        return $otp;
    }
  1. Update resources/views/livewire/pages/auth/login.blade.php such that the login function calls our new sendEmail method and redirects to the OTP entry page. You can also remove the password input field in this same file.
    public function login(): void
    {
        $this->validate();
    
        $otp = $this->form->sendEmail();
        
        $this->redirect($otp->url);
    }

Laravel Breeze Inertia Example

  1. Replace the Breeze provided App\Http\Requests\Auth\LoginRequest::authenticate method with a sendEmail method that runs the SendOtp action. Also be sure to remove password from the rules array.
    // app/Http/Requests/Auth/LoginRequest.php

    use BenBjurstrom\Otpz\Actions\SendOtp;
    use BenBjurstrom\Otpz\Exceptions\OtpThrottleException;
    use BenBjurstrom\Otpz\Models\Otp;
    //...
    
    public function rules(): array
    {
        return [
            'email' => ['required', 'string', 'email']
        ];
    }
    //...
    
    public function sendEmail(): Otp
    {
        $this->ensureIsNotRateLimited();
        RateLimiter::hit($this->throttleKey(), 300);

        try {
            $otp = (new SendOtp)->handle($this->email, $this->remember);
        } catch (OtpThrottleException $e) {
            throw ValidationException::withMessages([
                'email' => $e->getMessage(),
            ]);
        }

        RateLimiter::clear($this->throttleKey());

        return $otp;
    }
  1. Update the App\Http\Controllers\Auth\AuthenticatedSessionController::store method to call our new sendEmail method and redirect to the OTP entry page.
    public function store(LoginRequest $request): \Symfony\Component\HttpFoundation\Response
    {
        $otp = $request->sendEmail();

        return Inertia::location($otp->url);
    }
  1. Remove the password input field from the resources/js/Pages/Auth/Login.vue file.

Everything else is handled by the package components.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

signdeer/otpz 适用场景与选型建议

signdeer/otpz 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 769 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「Ben Bjurstrom」 「otpz」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 signdeer/otpz 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 signdeer/otpz 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-25