PHPackages                             pamellayamada/otphp - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. pamellayamada/otphp

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

pamellayamada/otphp
===================

Native, ultra-fast, and strictly typed engine for generating, validating, and rendering 2FA Tokens (TOTP/HOTP) in PHP 8.3+.

1.0.4(today)07↑2900%MITPHPPHP ^8.3CI failing

Since Aug 1Pushed todayCompare

[ Source](https://github.com/PamellaYamada/OTPHP)[ Packagist](https://packagist.org/packages/pamellayamada/otphp)[ Docs](https://github.com/pamellayamada/otphp)[ RSS](/packages/pamellayamada-otphp/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (6)Used By (0)

OTPHP 🔑
=======

[](#otphp-)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8f9b039bbc40012715629a9b10354b15b85294df31ca009cafffb4ef8998f292/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70616d656c6c6179616d6164612f6f747068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pamellayamada/otphp)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8aa9083993de0da593d9edef3c79ad556d9678ab10f2b189be70a741d06f43dd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f50616d656c6c6159616d6164612f6f747068702f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/PamellaYamada/otphp/actions)[![PHPStan Level 8](https://camo.githubusercontent.com/db5bead154012cb3076ec2e1d53be0b5c92a790e68be24f49ffa6abb0bbdf888/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230382d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://phpstan.org/)[![License: MIT](https://camo.githubusercontent.com/1b01ef0024ba0866c115986b895301f657c1b21fc29f05c4844b7f2e8d89204d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/a52d856792834f52285838dce8ad84578603723e73e932494282ed33a3eea7d8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e332d626c75652e7376673f7374796c653d666c61742d737175617265)](composer.json)

Native, high-performance, zero-dependency, internationalized, and strictly typed OTP (TOTP/HOTP) authentication engine for **PHP 8.3+**.

---

⚡ Key Features
--------------

[](#-key-features)

- 🚀 **Zero Dependencies:** Built entirely with native PHP features.
- 🎯 **Strictly Typed &amp; PSR Compliant:** PHPStan Level 8 static analysis and PSR-12/PER compliant.
- 🌐 **Internationalization (I18n):** Native multi-language support for exception messages and responses.
- 📱 **Native QR Code:** Renders clean SVG vector tags without external heavy image libraries (GD/Imagick).
- ⚙️ **Multi-Provider Support:** Pre-configured settings for Google Authenticator, Microsoft, Bitwarden, Steam Guard, YubiKey, Aegis, and more.

---

📦 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require pamellayamada/otphp
```

🚀 Usage
-------

[](#-usage)

### 1. Generating a Base32 Secret

[](#1-generating-a-base32-secret)

```
use PamellaYamada\OTPHP\OTPHP;

// Generate a secure Base32 secret key
$secret = OTPHP::createSecret(32);
```

### 2. Generating an OTP Code (TOTP)

[](#2-generating-an-otp-code-totp)

```
use PamellaYamada\OTPHP\OTPHP;
use PamellaYamada\OTPHP\Enums\OTPProvider;

// Generate the current 6-digit time-based code (Default: Google Authenticator)
$code = OTPHP::generate($secret);

// Or specify a target provider (e.g., Aegis with 8 digits)
$aegisCode = OTPHP::generate($secret, OTPProvider::AEGIS);
```

### 3. Verifying User Input

[](#3-verifying-user-input)

```
use PamellaYamada\OTPHP\OTPHP;

$userCode = '123456';

// Verify the code considering time drift (window parameter)
$isValid = OTPHP::verify($userCode,$secret, window: 1);

if ($isValid) {
    // Authentication successful
}
```

### 4. Rendering an SVG QR Code

[](#4-rendering-an-svg-qr-code)

```
use PamellaYamada\OTPHP\OTPHP;

// Returns a clean  string ready to embed into HTML, Blade, or PHP views
$svgXml = OTPHP::renderQrCodeSvg(
    secret: $secret,
    accountName: 'user@email.com',
    issuer: 'MyApp',
    sizePixels: 200
);

echo $svgXml;
```

### 5. Changing the Locale (I18n)

[](#5-changing-the-locale-i18n)

```
use PamellaYamada\OTPHP\OTPHP;
use PamellaYamada\OTPHP\Enums\OTPLanguage;

// Set global locale for exception messages and output
OTPHP::setLocale(OTPLanguage::EN_US);
```

🛠️ Development &amp; Quality Assurance
--------------------------------------

[](#️-development--quality-assurance)

This repository includes Composer scripts to ensure code quality:

```
# Run code formatting (Pint), static analysis (PHPStan Level 8), and unit tests (PHPUnit)
composer check

# Run unit tests only
composer test

# Format code using Laravel Pint
composer format

# Run PHPStan analysis
composer analyse
```

📄 License
---------

[](#-license)

This project is open-sourced software licensed under the MIT License.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance100

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

0d ago

PHP version history (2 changes)v1.0.1PHP &gt;=8.1

v1.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/e2ea037b6d89687f1c19de877cdbb01eb207856ec69de25c818204fc1c2791b8?d=identicon)[PamellaYamada](/maintainers/PamellaYamada)

---

Top Contributors

[![PamellaYamada](https://avatars.githubusercontent.com/u/49507325?v=4)](https://github.com/PamellaYamada "PamellaYamada (14 commits)")

---

Tags

phpqrcodegoogle authenticatorhotptotpsecurityAuthentication2fasvgtwo-factorSteam Guardotphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pamellayamada-otphp/health.svg)

```
[![Health](https://phpackages.com/badges/pamellayamada-otphp/health.svg)](https://phpackages.com/packages/pamellayamada-otphp)
```

###  Alternatives

[scheb/2fa-totp

Extends scheb/2fa-bundle with two-factor authentication using TOTP

293.5M58](/packages/scheb-2fa-totp)[jiripudil/otp

Library that generates and verifies one-time passwords.

2829.2k1](/packages/jiripudil-otp)[remotemerge/totp-php

Lightweight, fast, and secure TOTP (2FA) authentication library for PHP — battle tested, dependency free, and ready for enterprise integration.

2323.1k](/packages/remotemerge-totp-php)[kelunik/two-factor

Two factor authentication.

372.0k2](/packages/kelunik-two-factor)[eustasy/authenticatron

HOTP / TOTP secrets with corresponding QR links and code verification from a simple PHP script.

111.6k](/packages/eustasy-authenticatron)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
