dgtlinf/passwordless
Composer 安装命令:
composer require dgtlinf/passwordless
包简介
Headless Laravel package for passwordless authentication via magic link or OTP code
关键字:
README 文档
README
A modern, headless, and framework-agnostic passwordless authentication system for Laravel.
Easily send magic links and OTP codes without managing passwords.
🚀 Features
- 🔑 Passwordless login with OTP or magic link
- ⚙️ Configurable OTP length and type (numeric, alpha, alphanumeric)
- 🕒 Expiration control for tokens and magic links
- 📬 Notification-based delivery (email-ready, customizable channel)
- 🧩 Event-driven:
PasswordlessTokenCreated,PasswordlessTokenConsumed,PasswordlessLoginSucceeded - 🌍 Localization-ready (translations publishable)
- 🧪 100% test coverage with Pest + Orchestra Testbench
- 🧱 Fully decoupled — no frontend required
⚙️ Installation
composer require dgtlinf/passwordless
Then publish the configuration and migration with the easy install command:
php artisan passwordless:install
or you can just publish things separately:
php artisan vendor:publish --tag="passwordless-config" php artisan vendor:publish --tag="passwordless-migrations" php artisan migrate
🧩 Configuration
File: config/passwordless.php
Key sections:
models
Define which models to use.
You can override both the User model and the Token model.
'models' => [ 'user' => App\Models\User::class, 'token' => Dgtlinf\Passwordless\Models\PasswordlessToken::class, ],
notification
Define which notification class is used to deliver OTPs or links, and which route name generates the magic link.
'notification' => [ 'class' => Dgtlinf\Passwordless\Notifications\PasswordlessLoginNotification::class, 'route' => 'passwordless.magic', // used by URL::temporarySignedRoute() ],
otp
Configure OTP behavior.
'otp' => [ 'length' => 6, 'type' => 'numeric', // 'alpha' | 'alphanumeric' | 'numeric' ],
link
Configure token expiration for the magic link.
'link' => [ 'expire_minutes' => 30, 'token_length' => 64, ],
prune
Automatic cleanup for old tokens (via Laravel’s model pruning).
'prune' => [ 'enabled' => true, 'after_days' => 7, ],
🧠 Usage
1️⃣ Add the trait to your User model
use Dgtlinf\Passwordless\Traits\HasPasswordlessLogin; class User extends Authenticatable { use Notifiable, HasPasswordlessLogin; }
2️⃣ Trigger passwordless login
use Dgtlinf\Passwordless\Facades\Passwordless; Passwordless::send($user); // Sends OTP + magic link
3️⃣ Verify OTP or token
Passwordless::verifyOtp($user, $otp); // via code Passwordless::verifyToken($user, $token); // via magic link
🧩 Events
The following events are dispatched automatically and can be listened to in your app:
| Event | Description |
|---|---|
PasswordlessTokenCreated |
Fired when a token and OTP are generated |
PasswordlessTokenConsumed |
Fired when a token is successfully used |
PasswordlessLoginSucceeded |
Fired when login completes successfully |
Example listener registration (EventServiceProvider):
protected $listen = [ Dgtlinf\Passwordless\Events\PasswordlessLoginSucceeded::class => [ App\Listeners\LogPasswordlessLogin::class, ], ];
🌍 Translations
Translations are stored in resources/lang/vendor/passwordless/en/passwordless.php and can be published via:
php artisan vendor:publish --tag="passwordless-translations"
🧪 Testing
Run test suite:
vendor/bin/pest
All tests run using in-memory SQLite and are automatically configured via Orchestra Testbench.
🧾 License
Released under the MIT License.
Copyright © Digital Infinity DOO Novi Sad.
Website: digitalinfinity.rs
dgtlinf/passwordless 适用场景与选型建议
dgtlinf/passwordless 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「auth」 「laravel」 「otp」 「Passwordless」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dgtlinf/passwordless 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dgtlinf/passwordless 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dgtlinf/passwordless 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Multiauth package
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
This package provides a flexible way to add Role-based Permissions to Laravel 6.x
Email Toolkit Plugin for CakePHP
OTP generating package
OTP generating package
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-08