mohammed-abd-razaq/laravel-phone-otp-auth
Composer 安装命令:
composer require mohammed-abd-razaq/laravel-phone-otp-auth
包简介
A professional Laravel package for phone-based authentication with OTP verification, following clean architecture principles and Laravel best practices.
README 文档
README
A professional Laravel package for phone-based authentication with OTP verification, following clean architecture principles and Laravel best practices.
🚀 Features
- Phone-based Authentication - Login and register using phone numbers
- OTP Verification - Secure one-time password verification
- Password Reset - Phone-based password reset with OTP
- Clean Architecture - Repository pattern with service layer
- Laravel Standards - Follows Laravel package conventions
- Flexible Configuration - Customizable phone column and settings
- Multi-language Support - Built-in internationalization
- Professional Code - SOLID principles and clean code practices
📋 Requirements
- PHP 8.0+
- Laravel 9.0+
- Laravel Sanctum (for API tokens)
🔧 Installation
1. Install the Package
composer require mohammed-abd-razaq/laravel-phone-auth
2. Publish Configuration
php artisan vendor:publish --tag=auth-package-config
3. Run Migrations
php artisan migrate
4. Publish Language Files (Optional)
php artisan vendor:publish --tag=auth-package-lang
⚙️ Configuration
Environment Variables
Add these to your .env file:
AUTH_PHONE_COLUMN=phone AUTH_USER_MODEL=App\Models\User
Configuration Options
Edit config/auth-package.php:
return [ // Phone column name in users table 'phone_column' => env('AUTH_PHONE_COLUMN', 'phone'), // User model class 'user_model' => env('AUTH_USER_MODEL', 'App\Models\User'), // OTP settings 'otp_length' => 6, 'otp_expiration_minutes' => 30, 'max_verify_attempts' => 3, 'max_resend_count' => 3, 'resend_delay_minutes' => 1, 'verify_delay_minutes' => 1, 'suspend_time_minutes' => 120, ];
🛣️ API Endpoints
Public Routes
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/login |
Login with phone and password |
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/request-password-reset |
Request password reset |
| POST | /api/auth/verify-password-reset-otp |
Verify password reset OTP |
| POST | /api/auth/resend-password-reset-otp |
Resend password reset OTP |
Protected Routes
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/verify-otp |
Verify signup OTP |
| POST | /api/auth/resend-otp |
Resend signup OTP |
| POST | /api/auth/change-password |
Change password |
| POST | /api/auth/logout |
Logout user |
| GET | /api/auth/profile |
Get user profile |
📝 Usage Examples
Registration Flow
// 1. Register user (Public) $response = $this->post('/api/auth/register', [ 'name' => 'John Doe', 'phone' => '+1234567890', 'email' => 'john@example.com', 'password' => 'password123', ]); // 2. Verify OTP (Protected - requires token) $response = $this->withToken($token)->post('/api/auth/verify-otp', [ 'otp' => '123456', ]);
Login Flow
// Login (Public) $response = $this->post('/api/auth/login', [ 'phone' => '+1234567890', 'password' => 'password123', ]);
Password Reset Flow
// 1. Request password reset (Public) $response = $this->post('/api/auth/request-password-reset', [ 'phone' => '+1234567890', ]); // 2. Verify password reset OTP (Public) $response = $this->post('/api/auth/verify-password-reset-otp', [ 'phone' => '+1234567890', 'otp' => '123456', ]); // 3. Change password (Protected - requires token) $response = $this->withToken($token)->post('/api/auth/change-password', [ 'password' => 'newpassword123', ]);
🧪 Testing
The package includes comprehensive testing support:
- Unit Tests: Test individual components
- Feature Tests: Test complete workflows
- Integration Tests: Test API endpoints
Run tests with:
composer test
🔧 Customization
Custom Phone Column
If your users table uses a different column name:
AUTH_PHONE_COLUMN=mobile_number
Custom User Model
AUTH_USER_MODEL=App\Models\CustomUser
🛡️ Security Features
- OTP Expiration - OTPs expire after configurable time
- Rate Limiting - Prevents abuse of OTP requests
- Failed Attempt Tracking - Tracks and limits failed attempts
- Secure Token Management - Uses Laravel Sanctum
- Input Validation - Comprehensive request validation
- Phone Number Cleaning - Standardizes phone number format
🔄 Error Handling
The package provides consistent error responses:
{
"success": false,
"message": "Invalid phone number",
"errors": {
"phone": ["The phone number format is invalid"]
}
}
mohammed-abd-razaq/laravel-phone-otp-auth 适用场景与选型建议
mohammed-abd-razaq/laravel-phone-otp-auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「Authentication」 「sms」 「laravel」 「otp」 「clean-architecture」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mohammed-abd-razaq/laravel-phone-otp-auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mohammed-abd-razaq/laravel-phone-otp-auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mohammed-abd-razaq/laravel-phone-otp-auth 相关的其它包
同方向 / 同关键字的高下载量 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.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
A PSR-7 compatible library for making CRUD API endpoints
Email Toolkit Plugin for CakePHP
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-09