mincdev/php-otpauth

PHP library for Time-based One-Time Password (TOTP) authentication compatible with Google Authenticator, Microsoft Authenticator and Authy.

Maintainers

Package info

github.com/MincDev/php-otpauth

pkg:composer/mincdev/php-otpauth

Transparency log

Statistics

Installs: 36 976

Dependents: 0

Suggesters: 0

Stars: 5

Open Issues: 2

v2.0.0 2026-07-13 09:02 UTC

This package is auto-updated.

Last update: 2026-07-20 21:08:33 UTC


README

Tests Latest Version PHP Version Downloads License RFC 6238

A lightweight PHP library for generating and validating Time-based One-Time Passwords (TOTP) compatible with Google Authenticator, Microsoft Authenticator, Authy, 1Password, Bitwarden, and other RFC 6238 compatible authenticator applications.

Features

  • ๐Ÿ”’ Generate cryptographically secure TOTP secrets
  • ๐Ÿ“ฑ Generate QR codes for easy authenticator app provisioning
  • โœ… Validate one-time passwords
  • ๐Ÿงช Verified against the official RFC 6238 test vectors
  • ๐Ÿ–ฅ๏ธ QR codes are generated locally on your server โ€” no secrets are sent to third-party services
  • ๐Ÿš€ Lightweight with minimal dependencies

Installation

Install the package using Composer:

composer require mincdev/php-otpauth

Generating a Secret and QR Code

use MincDev\OtpAuth\OtpAuthenticator;

$otp = new OtpAuthenticator();

// Store the secret securely for the user.
$secret = $otp->newSecret();

$qrCode = $otp->getQR(
    'john.doe@example.com',
    'My Awesome App',
    $secret
);

The returned value is a Base64 data URI that can be used directly in an image tag:

<img src="<?= $qrCode ?>" alt="Authenticator QR Code">

Validating a Code

use MincDev\OtpAuth\OtpAuthenticator;

$otp = new OtpAuthenticator();

$isValid = $otp->validate($secret, $userEnteredCode);

Security

This library generates QR codes entirely on your server. The user's secret is never transmitted to an external QR code generation service, ensuring that sensitive authentication data remains under your control.

QR code generation is powered by tc-lib-barcode.

Compatibility

This library implements RFC 6238 (TOTP) and works with applications such as:

  • Google Authenticator
  • Microsoft Authenticator
  • Authy
  • 1Password
  • Bitwarden
  • and other compatible authenticator apps.

Testing

The TOTP implementation is verified against the official RFC 6238 test vectors to ensure standards-compliant code generation.

Run the test suite with:

composer test

License

Released under the MIT License.