PHPackages                             yaman-shahbander-dev/totp-generator - 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. yaman-shahbander-dev/totp-generator

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

yaman-shahbander-dev/totp-generator
===================================

A PHP implementation of Time-Based One-Time Password (TOTP), using Base32 encoding and HMAC hashing. Generates and verifies OTPs for secure authentication.

v1.1.1(12mo ago)22MITPHPPHP ^7.2|^8.0

Since May 15Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/yaman-shahbander-dev/laravel-totp)[ Packagist](https://packagist.org/packages/yaman-shahbander-dev/totp-generator)[ RSS](/packages/yaman-shahbander-dev-totp-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

laravel-totp
============

[](#laravel-totp)

A Laravel package for generating and verifying Time-Based One-Time Passwords (TOTP) compatible with RFC 6238. Provides both facade and contract-based implementations.

Features
========

[](#features)

- Generate TOTP codes
- Verify TOTP codes with configurable window
- Base32 encoding/decoding utilities
- Configurable parameters (period, digits, verification window)
- Laravel facade and service provider integration

Installation
============

[](#installation)

- Install via Composer:

```
composer require yaman-shahbander-dev/laravel-totp
```

- Publish the configuration file (optional):

```
php artisan vendor:publish --provider="TotpGenerator\Providers\TotpServiceProvider" --tag="config"
```

Configuration
=============

[](#configuration)

Default values in config/totp.php:

```
'default_period' => 30,      // Time step in seconds
'default_digits' => 6,       // Number of digits in OTP
'verification_window' => 1,  // Number of periods to check before/after
```

Usage
=====

[](#usage)

Using the Facade

```
use TotpGenerator\Facades\Totp;

// Generate a random secret (store this securely)
$secret = Str::random(16);
$base32Secret = Totp::encodeBase32($secret);

// Generate current TOTP
$code = Totp::generate($base32Secret);

// Verify a code
$isValid = Totp::verify($userCode, $base32Secret);

// With custom window
$isValid = Totp::verify($userCode, $base32Secret, 2);
```

Using Dependency Injection

```
use TotpGenerator\Contracts\TotpGeneratorContract;

class AuthController {
    public function __construct(
        protected TotpGeneratorContract $totp
    ) {}

    public function verifyCode(Request $request)
    {
        $isValid = $this->totp->verify(
            $request->code,
            $user->totp_secret
        );
    }
}
```

Direct Usage

```
$totp = app(TotpGeneratorContract::class);
$code = $totp->generate($base32Secret);
```

Base32 Utilities

```
// Encode binary to Base32
$base32Secret = Totp::encodeBase32(random_bytes(16));

// Decode Base32 to binary
$binarySecret = Totp::decodeBase32($base32Secret);
```

Security Considerations
=======================

[](#security-considerations)

- Always store secrets securely (encrypted at rest)
- Use secure random bytes for secret generation
- Consider rate limiting verification attempts
- The package uses SHA-1 by default (compatible with most authenticator apps)

License
=======

[](#license)

MIT License (see [LICENSE](https://mit-license.org/) file)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance50

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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

4

Last Release

363d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ceebd7147cba8294aa8332c7b293e134900dd3e8c77cb3272ef83dee7c254250?d=identicon)[yaman-shahbander-dev](/maintainers/yaman-shahbander-dev)

---

Top Contributors

[![mohamad-yaman-shahbandar](https://avatars.githubusercontent.com/u/154523997?v=4)](https://github.com/mohamad-yaman-shahbandar "mohamad-yaman-shahbandar (1 commits)")[![yaman-shahbander-dev](https://avatars.githubusercontent.com/u/154523997?v=4)](https://github.com/yaman-shahbander-dev "yaman-shahbander-dev (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yaman-shahbander-dev-totp-generator/health.svg)

```
[![Health](https://phpackages.com/badges/yaman-shahbander-dev-totp-generator/health.svg)](https://phpackages.com/packages/yaman-shahbander-dev-totp-generator)
```

###  Alternatives

[lab404/laravel-impersonate

Laravel Impersonate is a plugin that allows to you to authenticate as your users.

2.3k16.4M48](/packages/lab404-laravel-impersonate)[codegreencreative/laravel-samlidp

Make your PHP Laravel application an Identification Provider using SAML 2.0. This package allows you to implement your own Identification Provider (idP) using the SAML 2.0 standard to be used with supporting SAML 2.0 Service Providers (SP).

263763.5k1](/packages/codegreencreative-laravel-samlidp)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6712.1k2](/packages/hasinhayder-tyro)[truckersmp/steam-socialite

Laravel Socialite provider for Steam OpenID.

1516.7k](/packages/truckersmp-steam-socialite)[pschocke/laravel-telegram-login-widget

Easily integrate Telegrams login widget into your Laravel application to send Telegram messages

1610.4k](/packages/pschocke-laravel-telegram-login-widget)

PHPackages © 2026

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