PHPackages                             danterobles/totp-authenticator - 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. danterobles/totp-authenticator

ActiveLibrary[Security](/categories/security)

danterobles/totp-authenticator
==============================

A lightweight and secure PHP class for implementing TOTP two-factor authentication, compatible with Google Authenticator, Authy, and more.

v1.0.2(2mo ago)272[1 PRs](https://github.com/danterobles/TOTPAuthenticator/pulls)MITPHPPHP &gt;=7.0

Since Mar 31Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/danterobles/TOTPAuthenticator)[ Packagist](https://packagist.org/packages/danterobles/totp-authenticator)[ Docs](https://github.com/danterobles/TOTPAuthenticator)[ RSS](/packages/danterobles-totp-authenticator/feed)WikiDiscussions main Synced today

READMEChangelog (3)DependenciesVersions (4)Used By (0)

TOTP Authenticator for PHP
==========================

[](#totp-authenticator-for-php)

Overview
--------

[](#overview)

`TOTPAuthenticator` is a PHP class that implements Time-based One-Time Password (TOTP) authentication according to [RFC 6238](https://datatracker.ietf.org/doc/html/rfc6238). It provides a secure way to implement two-factor authentication (2FA) in your PHP applications, compatible with popular authenticator apps like Google Authenticator, Microsoft Authenticator, and Authy.

Features
--------

[](#features)

- Generate secure random secrets for TOTP authentication (minimum 128 bits / 16 bytes)
- Create and validate time-based one-time passwords
- Generate QR code URLs for easy setup with authenticator apps
- Generate backup codes for account recovery
- Input validation with descriptive exceptions for invalid configuration
- Customizable code length (6–8 digits) and time step
- Built-in Base32 encoding/decoding
- Full PHP 7.4+ type hints on all properties and methods
- Compatible with all standard TOTP authenticator applications

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- OpenSSL extension (for `random_bytes()`)

Installation
------------

[](#installation)

### Raw PHP

[](#raw-php)

Simply include the `TOTPAuthenticator.php` file in your project:

```
require_once 'path/to/TOTPAuthenticator.php';
```

### Composer / Laravel

[](#composer--laravel)

Install via Composer:

```
composer require danterobles/totp-authenticator
```

Or copy `src/TOTPAuthenticator.php` to your Laravel project and update the namespace:

```
