Download the PHP package hejunjie/google-authenticator without Composer
On this page you can find all versions of the php package hejunjie/google-authenticator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hejunjie/google-authenticator
More information about hejunjie/google-authenticator
Files in hejunjie/google-authenticator
Package google-authenticator
Short Description 一个用于生成和验证时间基础一次性密码(TOTP)的 PHP 包,支持 Google Authenticator 及类似应用。功能包括密钥生成、二维码创建和 OTP 验证 | A PHP library for generating and verifying Time-Based One-Time Passwords (TOTP). Compatible with Google Authenticator and similar apps, with features like secret generation, QR code creation, and OTP verification.
License MIT
Informations about the package google-authenticator
hejunjie/google-authenticator
English | 简体中文
A lightweight PHP TOTP authentication library for generating secrets, creating QR codes, and verifying Google Authenticator-compatible one-time passwords.
🔗 Quickly understand this project's structure and code logic via Zread.
Features
- 🔑 Generate secure Base32-encoded TOTP secrets
- 📱 Create QR code images with customizable size and logo
- ✅ Verify 6-digit OTP codes entered by users
- 🪶 Only depends on
endroid/qr-code, no other unnecessary dependencies - 🐘 Requires PHP >= 8.1, with strict typing support
Requirements
- PHP >= 8.1
- Composer
Installation
Quick Start
Generate a Secret
Generate a unique TOTP secret for each user. It is recommended to encrypt it before storing in the database.
Generate a QR Code
Generate a QR code image that users can scan with Google Authenticator to add the account.
| Parameter | Description | Default |
|---|---|---|
$issuer |
Application name, displayed as "issuer: label" in Authenticator | Required |
$label |
User identifier, displayed as "issuer: label" in Authenticator | Required |
$secret |
TOTP secret | Required |
$path |
File path for saving the QR code image (including filename) | Required |
$width |
Image width in pixels | 300 |
$logo |
Logo file path, pass an empty string to disable | '' |
$logo_width |
Logo width in pixels, ignored when $logo is empty |
50 |
Verify OTP
Verify the 6-digit code entered by the user.
The third optional parameter $timeWindow controls the time step (default 30 seconds), matching the Google Authenticator default setting. It generally does not need to be changed.
Notes
- Clock synchronization: TOTP relies on server time. Ensure NTP time synchronization is configured. The current implementation only verifies the current time window — a significant time skew between the server and user device may cause verification failures.
- Secret security: The secret is equivalent to a password. Store it securely (e.g., encrypted in the database). If leaked, an attacker can directly generate valid OTPs.
- File permissions: When generating QR codes, ensure the target directory exists and PHP has write permissions.