Download the PHP package ndtan/php-2fa without Composer
On this page you can find all versions of the php package ndtan/php-2fa. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ndtan/php-2fa
More information about ndtan/php-2fa
Files in ndtan/php-2fa
Informations about the package php-2fa
NDT 2FA (PHP)
TOTP (RFC 6238) for PHP with backup codes, otpauth URIs, and QR generation (SVG).
Ready for plain PHP, Laravel, and Symfony.
Table of Contents
- Features
- Installation
- Quick Start (Plain PHP)
- Backup Codes
- QR Codes
- Framework Integrations
- Laravel
- Symfony
- Secure Verification (Rate Limit + Replay Protection)
- API Reference
- Security Notes
- Testing
- License
Features
- ✅ TOTP (RFC 6238) — SHA1 / SHA256 / SHA512; configurable
digits/period/window - ✅ Base32 secrets — generate & decode for authenticator apps
- ✅ otpauth URIs — compatible with Google Authenticator, Authy, etc.
- ✅ Backup codes — plaintext generation + secure
password_hash/password_verify - ✅ QR generator (SVG Data URI) — via
endroid/qr-code - ✅ Security add-ons — Attempt limiter, replay protection, unified
Verifier - ✅ Frameworks — Laravel ServiceProvider (auto-discovery) & Symfony console command
- ✅ Zero-heavy deps — Only
endroid/qr-codefor QR (core TOTP is dependency-free)
Installation
PHP 8.1+ is required.
Quick Start (Plain PHP)
Tip: keep your server clock synchronized (NTP).
Backup Codes
QR Codes
The package includes an SVG QR provider (EndroidQrProvider) that returns a Data URI string you can embed directly in HTML <img> tags.
Framework Integrations
Laravel
- Auto-discovered provider:
ndtan\TwoFA\Laravel\NdtTwoFaServiceProvider - Container bindings:
ndt.twofa.totp→ TOTP utilitiesndt.twofa.qr→ QR provider (SVG)
Example (Controller):
Route middleware (optional):
Symfony
- Console command:
Prints the secret, otpauth URI, and QR (data URI).
Secure Verification (Rate Limit + Replay Protection)
Use the built-in AttemptLimiter, UsedCodeStore, and Verifier to harden your flow.
Distributed cache (Redis/Memcached) via PSR‑16:
See
docs/RATE_LIMITING.mdanddocs/SECURITY.mdfor details.
API Reference
Totp
generateSecret(int $bytes = 20): stringhotp(string $secretBase32, int $counter, int $digits = 6, string $algo = 'sha1'): stringtotp(string $secretBase32, int $period = 30, int $digits = 6, string $algo = 'sha1', ?int $timestamp = null): stringverify(string $secretBase32, string $code, int $period = 30, int $digits = 6, string $algo = 'sha1', int $window = 1, ?int $timestamp = null): array{valid:bool,delta:?int}buildOtpAuthUri(string $accountLabel, string $issuer, string $secretBase32, int $period = 30, int $digits = 6, string $algo = 'sha1'): string
BackupCodes
generate(int $count = 10, int $length = 10, ?string $alphabet = null): arrayhash(string $code): stringverify(string $code, string $hash): bool
Security utilities
AttemptLimiter::__construct(RateStoreInterface $store, int $maxAttempts = 5, int $perSeconds = 300, int $lockoutSeconds = 300)Verifier::verifyTotp(string $subjectKey, string $secretBase32, string $code): arrayArrayRateStore,Psr16RateStore,ArrayUsedCodeStore
Security Notes
- Store TOTP secrets encrypted at rest.
- Store backup codes as hashes only.
- Allow a small drift window (
window=1) and keep servers time‑synced (NTP). - Rate‑limit attempts and prevent code replay using the built‑in utilities.
Testing
License
MIT © Tony Nguyen