PHPackages                             makaveli/laravel-accept-code - 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. [Framework](/categories/framework)
4. /
5. makaveli/laravel-accept-code

ActiveLibrary[Framework](/categories/framework)

makaveli/laravel-accept-code
============================

Advanced Accept Code for Laravel

1.1.13(1mo ago)011MITPHPPHP ^8.2

Since Jul 21Pushed 1mo agoCompare

[ Source](https://github.com/Ma1kaveli/laravel-accept-code)[ Packagist](https://packagist.org/packages/makaveli/laravel-accept-code)[ RSS](/packages/makaveli-laravel-accept-code/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (12)Versions (23)Used By (0)

Laravel Accept Code
===================

[](#laravel-accept-code)

[![Packagist Version](https://camo.githubusercontent.com/8ce38a9982f8c3b6b690851779327bf9f564def020914663afd95b6e65afe322/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d616b6176656c692f6c61726176656c2d6163636570742d636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/makaveli/laravel-accept-code)[![Packagist Downloads](https://camo.githubusercontent.com/c09606b2273739d5bc88de4a39f6c66804d770e874dedd3dbb69c08165cbe385/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d616b6176656c692f6c61726176656c2d6163636570742d636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/makaveli/laravel-accept-code)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

🌍 Languages
-----------

[](#-languages)

- 🇺🇸 English (default)
- 🇷🇺 [Русская версия](docs/ru/README.md)

Table of Contents
-----------------

[](#table-of-contents)

1. [Introduction](#introduction)
2. [Requirements](#requirements)
3. [Installation](#installation)
4. [Configuration](#configuration)
5. [Core Components](#core-components)
    - [Actions](#actions)
    - [DTO](#dto)
    - [Repository](#repository)
    - [Service](#service)
    - [Requests](#requests)
    - [Model](#model)
    - [Console Commands](#console-commands)
6. [Usage](#usage)
    - [Login by Code](#login-by-code)
    - [Registration with Confirmation](#registration-with-confirmation)
    - [Password Reset](#password-reset)
7. [Extending the Package](#extending-the-package)
8. [Recommendations](#recommendations)
9. [Useful Links](#useful-links)

---

Introduction
------------

[](#introduction)

**makaveli/laravel-accept-code** is a package for managing one‑time verification codes (OTP) in Laravel. It implements typical scenarios: login by code (password‑less), registration with confirmation, and password reset. The package uses the `makaveli` ecosystem (JWT authentication, logging, CRUD layers) and can be easily integrated into any project.

Key features:

- Generation and sending of verification codes (email/SMS).
- Code validity checks with TTL and resend delay.
- Ready‑to‑use DTOs and requests for typical actions.
- Integration with `laravel-jwt-auth` to issue tokens after successful confirmation.
- Integration with `laravel-logger` for logging actions.
- Integration with `laravel-login-history` to record login history.
- Flexible configuration via callbacks (user lookup, notification sending, permission checks).

---

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Laravel 10.10, 11.0 or 12.0
- [makaveli/laravel-core](https://github.com/Ma1kaveli/laravel-core) (^1.0.4)
- [makaveli/laravel-logger](https://github.com/Ma1kaveli/laravel-logger) (^1.1.5)
- [makaveli/laravel-login-history](https://github.com/Ma1kaveli/laravel-login-history) (^1.1.5)
- [makaveli/laravel-jwt-auth](https://github.com/Ma1kaveli/laravel-jwt-auth) (^1.1.5)
- [makaveli/laravel-crudler](https://github.com/Ma1kaveli/laravel-crudler) (^1.1.21)

---

Installation
------------

[](#installation)

1. Install the package via Composer:

    ```
    composer require makaveli/laravel-accept-code
    ```
2. Run the migrations to create the `accept_codes` table:

    ```
    php artisan migrate:accept-code
    ```
3. (Optional) Publish the configuration file to adjust settings:

    ```
    php artisan vendor:publish --tag=accept-code-config
    ```

    This will create the file `config/accept-code.php`.

---

Configuration
-------------

[](#configuration)

The `config/accept-code.php` file contains the main settings. All callbacks are specified as arrays `[class, method]` or closures.

ParameterDescriptionDefault`accept_code_slugs`List of allowed slugs`['login', 'registration', 'reset-password']``get_user_by_phone`Callback to find a user by phone number`[\App\Modules\User\Repositories\UserRepository::class, 'getByPhone']``get_user_by_email`Callback to find a user by emailsimilar`get_user_role_id`Callback to get the user's role ID–`check_permission_to_auth`Callback to check permissions for authentication–`verified_user`Callback to set the `is_verified` flag–`change_password`Callback to change the password–`logger_slugs`Slugs for logging–`email`Callbacks for sending email–`phone`Callbacks for sending SMS–`accept_code_delay_repeat_ttl`Delay between resends (seconds)`90``accept_code_ttl`Code lifetime (seconds)`43200` (12 hours)`phone_validation_rule`Phone validation rule`ValidPhone::create()``password_validation_rule`Password validation rule`ValidPassword::create()`Example configuration:

```
return [
    'get_user_by_phone' => [\App\Modules\User\Repositories\UserRepository::class, 'getByPhone'],
    'get_user_by_email' => [\App\Modules\User\Repositories\UserRepository::class, 'getByEmail'],
    'verified_user' => [\App\Modules\Auth\Services\AuthService::class, 'verifiedUser'],
    'email' => [
        'send_verification_notification' => [\App\Modules\Email\Actions\EmailSenderActions::class, 'sendVerificationNotification'],
    ],
    'phone' => [
        'send_login_code' => [\App\Modules\Phone\Actions\MTCActions::class, 'sendLoginCode'],
    ],
    // ...
];
```

---

Core Components
---------------

[](#core-components)

### Actions

[](#actions)

The package provides three groups of actions:

- **`LoginAcceptCodeActions`** – sending and confirming a code for login.
- **`RegistrationAcceptCodeActions`** – sending and confirming a code for registration.
- **`ResetPasswordAcceptCodeActions`** – sending, verifying, and confirming a code for password reset.

Each class inherits from `AcceptCodeActions`, which contains common methods (transactions, logging, JWT generation, login history recording).

### DTO

[](#dto)

- **`AcceptCodeDTO`** – a universal DTO for passing data between request and action. Contains fields: `login`, `isPortal`, `code`, `type`, `captchaToken`, `password`, `request`.
    Static methods: `fromRegistrationSendRequest`, `fromRegistrationAcceptAccountRequest`, `fromLoginSendRequest`, `fromLoginAcceptRequest`, `fromPasswordResetSendRequest`, `fromPasswordResetVerifyRequest`, `fromPasswordResetSetNewRequest`.
- **`AcceptCodeFormDTO`** – a DTO for creating/updating a code record. Contains: `userId`, `credetinal`, `slug`, `type`, `userVerified`.
    Static methods: `fromCredetinalsPhone`, `fromCredetinals`.

### Repository

[](#repository)

**`AcceptCodeRepository`** extends `BaseRepository` and contains methods for working with codes:

- `getSendAcceptCodeByUserId` – get the last sent code for a user.
- `getSendAcceptCode` – get a code by credentials and slug.
- `checkDelayIsOver` – checks whether a new code can be sent (delay not exceeded).
- `acceptCodeIsValid` – checks whether the code has not expired.
- `getAcceptCode` – generic method to fetch a code with existence and TTL checks.
- `canSendLoginAcceptCode`, `canSendPasswordResetCode`, `canSendRegistrationAcceptCode` – checks whether sending is allowed.

### Service

[](#service)

**`AcceptCodeService`** extends `BaseService` and is responsible for creating/updating code records:

- `_create(AcceptCodeFormDTO $dto)` – creates a new record with a random 4‑digit code.
- `createOrUpdate(AcceptCodeFormDTO $dto)` – updates an existing record or creates a new one.

### Requests

[](#requests)

The package includes ready‑made FormRequests for each endpoint:

- `LoginSendCodeRequest`
- `LoginAcceptCodeRequest`
- `RegistrationSendCodeRequest`
- `RegistrationAcceptAccountRequest`
- `PasswordResetSendRequest`
- `PasswordResetVerifyRequest`
- `PasswordResetSetNewRequest`

All of them extend `FormRequest` and use validation rules from the configuration.

### Model

[](#model)

**`AcceptCode`** – Eloquent model with fields `user_id`, `credetinal`, `code`, `type`, `slug`. Used to store codes.

### Console Commands

[](#console-commands)

- `php artisan migrate:accept-code` – runs the package migrations.

---

Usage
-----

[](#usage)

### Login by Code

[](#login-by-code)

1. **Send code**

```
use AcceptCode\Actions\LoginAcceptCodeActions;
use AcceptCode\DTO\AcceptCodeDTO;

$actions = new LoginAcceptCodeActions();
$dto = AcceptCodeDTO::fromLoginSendRequest($request);
$actions->sendLoginCode($dto); // returns true or throws an exception
```

2. **Confirm code and authenticate**

```
[$accessToken, $refreshToken, $user] = $actions->acceptLoginCodeAndAuth(
    AcceptCodeDTO::fromLoginAcceptRequest($request)
);
// You can return the tokens and user data in the response
```

### Registration with Confirmation

[](#registration-with-confirmation)

1. **Send registration code**

```
use AcceptCode\Actions\RegistrationAcceptCodeActions;

$actions = new RegistrationAcceptCodeActions();
$dto = AcceptCodeDTO::fromRegistrationSendRequest($request);
$actions->sendRegistrationCode($dto);
```

2. **Confirm code and generate tokens**

```
[$accessToken, $refreshToken, $user] = $actions->acceptRegistrationCode(
    AcceptCodeDTO::fromRegistrationAcceptAccountRequest($request)
);
```

### Password Reset

[](#password-reset)

1. **Send password reset code**

```
use AcceptCode\Actions\ResetPasswordAcceptCodeActions;

$actions = new ResetPasswordAcceptCodeActions();
$dto = AcceptCodeDTO::fromPasswordResetSendRequest($request);
$actions->sendResetPasswordCode($dto);
```

2. **Verify code (optional step)**

```
$actions->verifyResetPasswordCode(
    AcceptCodeDTO::fromPasswordResetVerifyRequest($request)
);
// if the code is invalid or expired, an exception will be thrown
```

3. **Set new password**

```
$user = $actions->acceptResetPasswordCode(
    AcceptCodeDTO::fromPasswordResetSetNewRequest($request)
);
```

---

Extending the Package
---------------------

[](#extending-the-package)

You can replace any part of the package by overriding:

- **Model** – create your own model extending `AcceptCode`, and change `$table` if needed.
- **Repository** – extend `AcceptCodeRepository` and override methods for custom logic.
- **Service** – extend `AcceptCodeService` and override `_create` or `createOrUpdate`.
- **Actions** – create your own classes extending `AcceptCodeActions` and override the necessary methods.
- **DTO and Request** – use them directly or create your own by extending the base classes.

All dependencies (logging, JWT, login history) are placed in traits that can be overridden in your own action.

---

Recommendations
---------------

[](#recommendations)

- **Configure the callbacks in the config file** – specify your own methods for user lookup, sending notifications, and permission checks.
- **Use asynchronous logging** – actions already use `successAsyncLog` and `errorAsyncLog` via the `AsyncLogger` trait.
- **Set reasonable TTLs** – adjust `accept_code_ttl` and `accept_code_delay_repeat_ttl` according to your security requirements.
- **Protect endpoints from spam** – add a captcha (e.g., `captchaToken` is already present in the DTO) and configure rate limits.
- **For email confirmation** – set up email notifications in the `email` section.
- **For SMS confirmation** – specify your SMS services in the `phone` section.

---

Useful Links
------------

[](#useful-links)

- Package repository:
- Dependencies:
    - [makaveli/laravel-core](https://github.com/Ma1kaveli/laravel-core)
    - [makaveli/laravel-jwt-auth](https://github.com/Ma1kaveli/laravel-jwt-auth)
    - [makaveli/laravel-logger](https://github.com/Ma1kaveli/laravel-logger)
    - [makaveli/laravel-login-history](https://github.com/Ma1kaveli/laravel-login-history)
    - [makaveli/laravel-crudler](https://github.com/Ma1kaveli/laravel-crudler)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance91

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

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

Every ~12 days

Recently: every ~0 days

Total

22

Last Release

43d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed91cef75c6ac70dbc36843a28453115d78996faf342c9d0f86d89283b751522?d=identicon)[Ma1kaveli](/maintainers/Ma1kaveli)

---

Top Contributors

[![Ma1kaveli](https://avatars.githubusercontent.com/u/74207027?v=4)](https://github.com/Ma1kaveli "Ma1kaveli (22 commits)")

---

Tags

frameworklaravel

### Embed Badge

![Health badge](/badges/makaveli-laravel-accept-code/health.svg)

```
[![Health](https://phpackages.com/badges/makaveli-laravel-accept-code/health.svg)](https://phpackages.com/packages/makaveli-laravel-accept-code)
```

###  Alternatives

[codewithdennis/larament

Larament is a time-saving starter kit to quickly launch Laravel 13.x projects. It includes FilamentPHP 5.x pre-installed and configured, along with additional tools and features to streamline your development workflow.

3691.5k](/packages/codewithdennis-larament)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11812.4k21](/packages/kompo-kompo)

PHPackages © 2026

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