Download the PHP package elgibor-solution/laravel-2fa without Composer
On this page you can find all versions of the php package elgibor-solution/laravel-2fa. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elgibor-solution/laravel-2fa
More information about elgibor-solution/laravel-2fa
Files in elgibor-solution/laravel-2fa
Package laravel-2fa
Short Description Two-Factor Authentication package for Laravel supporting Google Authenticator (TOTP) and self-generated codes via SMS/WhatsApp/Email.
License Apache-2.0
Informations about the package laravel-2fa
elgibor-solution/laravel-2fa
Two-Factor Authentication package for Laravel that supports:
- Google Authenticator (TOTP)
- Self-generated one-time codes with configurable expiry
- Delivery via Email (built-in), SMS, or WhatsApp (user-provided callbacks)
- Built-in fraud protection: attempt limits, cooldowns, per-user lock
Requirements
- PHP 8.1+
- Laravel 10 or 11
Installation
Publish config and (optionally) migrations:
Configuration
config/2fa.php
channels.email/sms/whatsapp— enable built-in email sender; provide SMS/WhatsApp callbacks.self_generated_ttl— expiry (seconds) for self-generated codes.code_length— digits for self-generated codes.max_attempts,lock_minutes_after_max— fraud control.cooldown_seconds_between_requests— min time between code requests.totp_drift— allowed time drift for TOTP.issuer— shown in Google Authenticator.tables— override table names if needed.
Binding SMS / WhatsApp senders
In AppServiceProvider@boot() or any service provider:
Email is supported out of the box via Mail::raw().
Routes
These routes are auto-registered under /2fa with web,auth middleware.
POST /2fa/init-totp→ Start TOTP setup. Returns{ secret, otpauth_uri }.POST /2fa/confirm-totp→ Enable TOTP (body:code).POST /2fa/disable→ Disable 2FA for the authenticated user.POST /2fa/create→ Generate self code and send (body:channel, destination, purpose?).POST /2fa/validate→ Validate any code (body:code, purpose?).
Using the Facade
Generating a QR Code for Google Authenticator
initTotp() returns an otpauth:// URI. Render a QR code on your frontend using any QR library (e.g., JavaScript QR libraries). Users can scan that QR with Google Authenticator.
Fraud & Security
- Hashed codes at rest (HMAC-SHA256 with
APP_KEY). Sethash_codes=falseto store plaintext (not recommended). - Per-code attempt limit (config
max_attempts). - Cooldown between requests (
cooldown_seconds_between_requests). - Temporary account lock after too many failures (
lock_minutes_after_max). Lock status is tracked intwo_fa_settings.locked_until. - IP & User-Agent logging for every action in
two_fa_logs.
Tip: Add additional monitoring or alerts by listening to model events or querying
two_fa_logs.
Middleware
An optional middleware ESolution\Laravel2FA\Http\Middleware\Enforce2FA is included. It blocks requests if the account is currently locked. Register it in app/Http/Kernel.php and apply where needed.
Database
two_fa_settings: per-user status, method (totporself), secret, lock.two_fa_codes: self-generated codes, expiry, attempts, delivery channel.two_fa_logs: audit log of events.
Testing Locally
- Enable mail logging (e.g.,
MAIL_MAILER=log) to see email messages in logs. - For SMS/WhatsApp, just bind callbacks that
Log::info()the outbound text.
Support & Hiring
Need professional help or want to move faster? Hire the E-Solution / Elgibor team for integration, audits, or custom features.
📧 [email protected]
Donations
If this package saves you time, consider supporting development ❤️
License
Apache-2.0
All versions of laravel-2fa with dependencies
illuminate/support Version ^10.0|^11.0
illuminate/mail Version ^10.0|^11.0
ext-json Version *