PHPackages                             mohammed-abd-razaq/laravel-phone-otp-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. mohammed-abd-razaq/laravel-phone-otp-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

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.

1.0.0(9mo ago)01MITPHPPHP ^8.0CI failing

Since Aug 3Pushed 9mo agoCompare

[ Source](https://github.com/MOHAMMED-ABD-RAZAQ/laravel-phone-otp-auth)[ Packagist](https://packagist.org/packages/mohammed-abd-razaq/laravel-phone-otp-auth)[ RSS](/packages/mohammed-abd-razaq-laravel-phone-otp-auth/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

Laravel Phone Authentication Package
====================================

[](#laravel-phone-authentication-package)

A professional Laravel package for phone-based authentication with OTP verification, following clean architecture principles and Laravel best practices.

🚀 Features
----------

[](#-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
--------------

[](#-requirements)

- PHP 8.0+
- Laravel 9.0+
- Laravel Sanctum (for API tokens)

🔧 Installation
--------------

[](#-installation)

### 1. Install the Package

[](#1-install-the-package)

```
composer require mohammed-abd-razaq/laravel-phone-auth
```

### 2. Publish Configuration

[](#2-publish-configuration)

```
php artisan vendor:publish --tag=auth-package-config
```

### 3. Run Migrations

[](#3-run-migrations)

```
php artisan migrate
```

### 4. Publish Language Files (Optional)

[](#4-publish-language-files-optional)

```
php artisan vendor:publish --tag=auth-package-lang
```

⚙️ Configuration
----------------

[](#️-configuration)

### Environment Variables

[](#environment-variables)

Add these to your `.env` file:

```
AUTH_PHONE_COLUMN=phone
AUTH_USER_MODEL=App\Models\User
```

### Configuration Options

[](#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
----------------

[](#️-api-endpoints)

### Public Routes

[](#public-routes)

MethodEndpointDescriptionPOST`/api/auth/login`Login with phone and passwordPOST`/api/auth/register`Register new userPOST`/api/auth/request-password-reset`Request password resetPOST`/api/auth/verify-password-reset-otp`Verify password reset OTPPOST`/api/auth/resend-password-reset-otp`Resend password reset OTP### Protected Routes

[](#protected-routes)

MethodEndpointDescriptionPOST`/api/auth/verify-otp`Verify signup OTPPOST`/api/auth/resend-otp`Resend signup OTPPOST`/api/auth/change-password`Change passwordPOST`/api/auth/logout`Logout userGET`/api/auth/profile`Get user profile📝 Usage Examples
----------------

[](#-usage-examples)

### Registration Flow

[](#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-flow)

```
// Login (Public)
$response = $this->post('/api/auth/login', [
    'phone' => '+1234567890',
    'password' => 'password123',
]);
```

### Password Reset Flow

[](#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
---------

[](#-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
---------------

[](#-customization)

### Custom Phone Column

[](#custom-phone-column)

If your users table uses a different column name:

```
AUTH_PHONE_COLUMN=mobile_number
```

### Custom User Model

[](#custom-user-model)

```
AUTH_USER_MODEL=App\Models\CustomUser
```

🛡️ Security Features
--------------------

[](#️-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
----------------

[](#-error-handling)

The package provides consistent error responses:

```
{
    "success": false,
    "message": "Invalid phone number",
    "errors": {
        "phone": ["The phone number format is invalid"]
    }
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance57

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

282d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/230cc8bbf5028a489090673e4bcee435a359b5ab27616b4683d332ed10bbdf95?d=identicon)[MOHAMMED-ABD-RAZAQ](/maintainers/MOHAMMED-ABD-RAZAQ)

---

Top Contributors

[![MOHAMMED-ABD-RAZAQ](https://avatars.githubusercontent.com/u/29556066?v=4)](https://github.com/MOHAMMED-ABD-RAZAQ "MOHAMMED-ABD-RAZAQ (4 commits)")

---

Tags

apilaravelotpAuthenticationsmsclean architecturepassword-resetphone-auth

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mohammed-abd-razaq-laravel-phone-otp-auth/health.svg)

```
[![Health](https://phpackages.com/badges/mohammed-abd-razaq-laravel-phone-otp-auth/health.svg)](https://phpackages.com/packages/mohammed-abd-razaq-laravel-phone-otp-auth)
```

###  Alternatives

[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6712.1k2](/packages/hasinhayder-tyro)[salehhashemi/laravel-otp-manager

Laravel OTP manager

18713.2k](/packages/salehhashemi-laravel-otp-manager)[lakm/nopass

Provides passwordless authentication for your laravel projects.

2213.6k2](/packages/lakm-nopass)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
