PHPackages                             andydefer/laravel-mfa - 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. [Security](/categories/security)
4. /
5. andydefer/laravel-mfa

ActiveLibrary[Security](/categories/security)

andydefer/laravel-mfa
=====================

Laravel MFA: A flexible, multi-purpose Multi-Factor Authentication management system for Laravel applications with support for OTP (email/sms), TOTP (Google Authenticator), passwordless login, 2FA, and action confirmation.

2.0.1(1mo ago)03MITPHPPHP &gt;=8.1

Since Apr 26Pushed 1mo agoCompare

[ Source](https://github.com/andydefer/laravel-mfa)[ Packagist](https://packagist.org/packages/andydefer/laravel-mfa)[ Docs](https://github.com/andydefer/laravel-mfa)[ RSS](/packages/andydefer-laravel-mfa/feed)WikiDiscussions main Synced 1w ago

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

Laravel MFA (Multi-Factor Authentication)
=========================================

[](#laravel-mfa-multi-factor-authentication)

[![Latest Version on Packagist](https://camo.githubusercontent.com/039dad077de94c6b6b664717910aa3b18a89edbf6262e8dbea6f338c6e3a3c94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e647964656665722f6c61726176656c2d6d66612e737667)](https://packagist.org/packages/andydefer/laravel-mfa)[![PHP Version Require](https://camo.githubusercontent.com/e02f14527242fc197fa8716890af6589510fe85dcbd901fdaba189f5d9b98584/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616e647964656665722f6c61726176656c2d6d66612e737667)](https://packagist.org/packages/andydefer/laravel-mfa)[![Laravel Version](https://camo.githubusercontent.com/b72e0aa3b09f6ee9f1cd47f19792a8204408312803c6b277768a5d2c99ffd60c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322e782d7265642e737667)](https://laravel.com)[![License](https://camo.githubusercontent.com/4cf353f9cc5edc352b9038090ffab0ed3445b8536e5e6097a09924fcc8882a59/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616e647964656665722f6c61726176656c2d6d66612e737667)](https://packagist.org/packages/andydefer/laravel-mfa)[![Total Downloads](https://camo.githubusercontent.com/02acf959a005d03345e06f8c854c6671f5e9a7c5c18943579b732bc2c629097d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e647964656665722f6c61726176656c2d6d66612e737667)](https://packagist.org/packages/andydefer/laravel-mfa)

Un package complet de Multi-Factor Authentication pour Laravel 12, supportant OTP (email/SMS) et TOTP (Google Authenticator).

✨ Fonctionnalités
-----------------

[](#-fonctionnalités)

- **🔑 OTP (One-Time Password)** - Envoi et vérification de codes à usage unique par email ou SMS
- **🔐 TOTP (Time-based One-Time Password)** - Authentification à deux facteurs compatible Google Authenticator
- **📱 QR Codes** - Génération automatique de QR codes pour l'application Google Authenticator
- **🔁 Codes de récupération** - Génération de codes de secours pour récupérer l'accès
- **⏱️ Rate Limiting** - Protection contre les attaques par force brute
- **🌍 Multilingue** - Support français et anglais inclus (extensible)
- **🧹 Auto-cleanup** - Nettoyage automatique des OTPs expirés et anciennes configurations 2FA
- **🔄 Polymorphique** - Supporte n'importe quel modèle Eloquent (User, Admin, etc.)

📋 Prérequis
-----------

[](#-prérequis)

- PHP 8.1 ou supérieur
- Laravel 12.x
- Composer

🚀 Installation
--------------

[](#-installation)

### 1. Installer via Composer

[](#1-installer-via-composer)

```
composer require andydefer/laravel-mfa
```

### 2. Publier les fichiers de configuration et migrations

[](#2-publier-les-fichiers-de-configuration-et-migrations)

```
php artisan mfa:install
```

Cette commande va :

- Publier le fichier de configuration `config/mfa.php`
- Publier les migrations OTP et TOTP
- Exécuter les migrations

**Options disponibles :**

```
# Forcer l'installation sans confirmation
php artisan mfa:install --force

# Installer sans exécuter les migrations
php artisan mfa:install --no-migrate

# Installer uniquement l'OTP (sans le 2FA/TOTP)
php artisan mfa:install --without-totp

# Installer uniquement le TOTP/2FA (sans l'OTP)
php artisan mfa:install --without-otp
```

### 3. Migrer la base de données (si non fait automatiquement)

[](#3-migrer-la-base-de-données-si-non-fait-automatiquement)

```
php artisan migrate
```

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

[](#️-configuration)

### Variables d'environnement

[](#variables-denvironnement)

Créez/modifiez les variables suivantes dans votre fichier `.env` :

```
# OTP Settings
MFA_OTP_DEFAULT_EXPIRY_MINUTES=10
MFA_OTP_DEFAULT_MAX_ATTEMPTS=3
MFA_OTP_LOCALE=en
MFA_OTP_RATE_LIMIT_REQUESTS=3
MFA_OTP_RATE_LIMIT_VERIFICATIONS=5

# TOTP Settings
MFA_TOTP_PERIOD=30
MFA_TOTP_DIGITS=6
MFA_TOTP_ALGORITHM=sha1
MFA_TOTP_WINDOW=1
MFA_TOTP_ISSUER=MyApplication

# Recovery Codes
MFA_RECOVERY_CODES_COUNT=8
MFA_RECOVERY_CODE_LENGTH=10
MFA_RECOVERY_CODE_HASH_ALGO=sha256

# Cleanup
MFA_CLEANUP_AUTO_CLEANUP=true
MFA_CLEANUP_RETENTION_DAYS=30
```

### Fichier de configuration

[](#fichier-de-configuration)

Après installation, vous pouvez personnaliser `config/mfa.php` :

```
return [
    'otp' => [
        'default_expiry_minutes' => env('MFA_OTP_DEFAULT_EXPIRY_MINUTES', 10),
        'default_max_attempts' => env('MFA_OTP_DEFAULT_MAX_ATTEMPTS', 3),
        'localization' => [
            'locale' => env('MFA_OTP_LOCALE', 'en'),
            'supported_locales' => ['fr', 'en'],
            'fallback_locale' => env('MFA_OTP_FALLBACK_LOCALE', 'en'),
        ],
        // ... autres configurations
    ],
    'totp' => [
        'period' => env('MFA_TOTP_PERIOD', 30),
        'digits' => env('MFA_TOTP_DIGITS', 6),
        'algorithm' => env('MFA_TOTP_ALGORITHM', 'sha1'),
        'issuer' => env('MFA_TOTP_ISSUER', config('app.name')),
        'window' => env('MFA_TOTP_WINDOW', 1),
    ],
    // ...
];
```

🔧 Utilisation
-------------

[](#-utilisation)

### 1. Préparer votre modèle User

[](#1-préparer-votre-modèle-user)

Ajoutez les traits à votre modèle `User` :

```
