Skip to content

Repository files navigation

Maatify Verification Module

Latest VersionPHP VersionLicenseCI

PHPStanPHP

Monthly DownloadsTotal Downloads

ChangelogSecuritySecurity Audit

VerificationFrameworkMaatify

Install

Overview

The Maatify\Verification module is a framework-agnostic verification code component designed for managing One-Time Passwords (OTPs) and temporary codes. It handles the complete lifecycle of verification codes, including generation, secure storage (hashing), validation, attempt tracking, expiration, and IP address auditing.

Installation

Install the package via Composer:

composer require maatify/verification

Architecture Summary

This module follows Domain-Driven Design (DDD) principles with strict separation between the domain logic and infrastructure concerns:

  • Domain Layer: Contains core contracts (VerificationCodeGeneratorInterface, VerificationCodeValidatorInterface), DTOs (VerificationCode, GeneratedVerificationCode), and Services (VerificationCodeGenerator, VerificationCodeValidator) implementing the business rules for verification codes.
  • Infrastructure Layer: Implements data persistence. By default, it includes PdoVerificationCodeRepository for database storage.
  • Bootstrap Layer: Provides dependency injection container bindings (VerificationBindings) to ease integration.

Module Structure

src/
├── Bootstrap/ # DI Container bindings
│ └── VerificationBindings.php
├── Domain/
│ ├── Contracts/ # Core interfaces
│ ├── DTO/ # Data Transfer Objects
│ ├── Enum/ # Strongly-typed Enums for state and types
│ └── Service/ # Business logic for generation and validation
├── Infrastructure/
│ └── Repository/ # Persistence implementations (e.g., PDO)
├── docs/ # Extensive documentation
└── composer.json # Standalone package definition

Quick Usage

To quickly get started with the module, register the bindings in your DI container and use the provided services:

useMaatify\Verification\Bootstrap\VerificationBindings;
useMaatify\Verification\Domain\Contracts\VerificationCodeGeneratorInterface;
useMaatify\Verification\Domain\Contracts\VerificationCodeValidatorInterface;
useMaatify\Verification\Domain\Enum\IdentityTypeEnum;
useMaatify\Verification\Domain\Enum\VerificationPurposeEnum;
// 1. Register bindings
VerificationBindings::register($containerBuilder);
// 2. Generate a verification code/** @var VerificationCodeGeneratorInterface $generator */$generator = $container->get(VerificationCodeGeneratorInterface::class);
$generated = $generator->generate(
IdentityTypeEnum::Email,
'user@example.com',
VerificationPurposeEnum::EmailVerification,
'192.168.1.100'// Optional IP tracking
);
// Send $generated->plainCode to the user...// 3. Validate a verification code/** @var VerificationCodeValidatorInterface $validator */$validator = $container->get(VerificationCodeValidatorInterface::class);
$result = $validator->validate(
IdentityTypeEnum::Email,
'user@example.com',
VerificationPurposeEnum::EmailVerification,
'123456', // The plain code provided by the user'192.168.1.101'// Optional IP tracking for usage
);
if ($result->success) {
// Verification successful
} else {
// Verification failed: $result->reason
}

Further Documentation

Documentation Book

Comprehensive architecture and integration guides are available in the Book:

ChapterDescription
Table of ContentsMain entry point for the documentation book.
01. OverviewHigh-level module concepts and goals.
02. ArchitectureDetailed layer boundaries and responsibilities.
03. Domain ModelEntities, DTOs, and Enums representing the verification state.
04. Verification LifecycleThe strict lifecycle rules from creation to expiration.
05. Code GenerationHow codes are generated, hashed, and policies applied.
06. Code ValidationThe validation process, attempt tracking, and anti-brute-force.
07. Repository LayerData persistence strategies and infrastructure.
08. Container BindingsConnecting the module to Dependency Injection containers.
09. Extension PointsExtending policies, storage, and identifier types.
10. Integration PatternsReal-world usage inside larger applications.
11. Common PitfallsMistakes to avoid when implementing the module.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Framework-agnostic OTP and verification code lifecycle manager.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages