PHPackages                             joanfabregat/secure-token-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. [Security](/categories/security)
4. /
5. joanfabregat/secure-token-generator

ActiveLibrary[Security](/categories/security)

joanfabregat/secure-token-generator
===================================

Generate cryptographically secure alphanumeric tokens in PHP

v1.4(2mo ago)0221MITPHPPHP &gt;=8.2CI passing

Since Apr 29Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/joanfabregat/secure-token-generator)[ Packagist](https://packagist.org/packages/joanfabregat/secure-token-generator)[ Docs](https://github.com/joanfabregat/secure-token-generator)[ RSS](/packages/joanfabregat-secure-token-generator/feed)WikiDiscussions main Synced yesterday

READMEChangelog (5)Dependencies (3)Versions (7)Used By (0)

Secure token generator
======================

[](#secure-token-generator)

[![CI](https://github.com/joanfabregat/secure-token-generator/actions/workflows/ci.yml/badge.svg)](https://github.com/joanfabregat/secure-token-generator/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/2413362c68c35b51d2dd105944fbd62fb643fd8acf36bdc0e0b2e5507274cd3b/68747470733a2f2f706f7365722e707567782e6f72672f6a6f616e66616272656761742f7365637572652d746f6b656e2d67656e657261746f722f76)](https://packagist.org/packages/joanfabregat/secure-token-generator)[![Total Downloads](https://camo.githubusercontent.com/b162c3558ed9ccc92540ea25feab2f7d30b8d0951c6fe82723b3b6877f298a80/68747470733a2f2f706f7365722e707567782e6f72672f6a6f616e66616272656761742f7365637572652d746f6b656e2d67656e657261746f722f646f776e6c6f616473)](https://packagist.org/packages/joanfabregat/secure-token-generator)[![License](https://camo.githubusercontent.com/4b3dad5a4b89bc48a467b8ca6b0aea2d9838e7d5fa041cde9e69b0a2407bfe18/68747470733a2f2f706f7365722e707567782e6f72672f6a6f616e66616272656761742f7365637572652d746f6b656e2d67656e657261746f722f6c6963656e7365)](https://packagist.org/packages/joanfabregat/secure-token-generator)

Generate cryptographically secure tokens in PHP 8.2+ using PHP [`random_int()`](https://www.php.net/manual/en/function.random-int.php).

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

[](#installation)

```
composer require joanfabregat/secure-token-generator
```

Usage
-----

[](#usage)

```
use JoanFabregat\SecureTokenGenerator\SecureTokenGenerator;

// A simple alphanumeric token
$token = SecureTokenGenerator::generate(16);

// With all the options
$token = SecureTokenGenerator::generate(
    length: 32,
    allowDigits: true,        // 0-9
    allowSpecialChars: true,  // !"#$%&'()*+,-./
    allowUppercase: true,     // A-Z
    allowLowercase: true,     // a-z
);

// An integer token (e.g. 6-digit OTP)
$otp = SecureTokenGenerator::generateInt(6);
// $otp is an int between 100000 and 999999
```

License
-------

[](#license)

MIT — see [`LICENSE`](LICENSE).

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance85

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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 ~179 days

Total

5

Last Release

79d ago

### Community

Maintainers

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

---

Top Contributors

[![joanfabregat](https://avatars.githubusercontent.com/u/4227907?v=4)](https://github.com/joanfabregat "joanfabregat (16 commits)")

---

Tags

randomsecuritypasswordgeneratortoken

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/joanfabregat-secure-token-generator/health.svg)

```
[![Health](https://phpackages.com/badges/joanfabregat-secure-token-generator/health.svg)](https://phpackages.com/packages/joanfabregat-secure-token-generator)
```

###  Alternatives

[rych/phpass

PHP Password Library: Easy, secure password management for PHP

248850.1k4](/packages/rych-phpass)[passwordlib/passwordlib

A Password Hashing Library

377223.2k7](/packages/passwordlib-passwordlib)[bordoni/phpass

Portable PHP password hashing framework

254.7M30](/packages/bordoni-phpass)[jeremykendall/password-validator

Password Validator validates password\_hash generated passwords, rehashes passwords as necessary, and will upgrade legacy passwords.

14470.7k3](/packages/jeremykendall-password-validator)[nicobleiler/php-passphrase

Passphrase generator with Laravel integration, inspired by Bitwarden. Uses the EFF long word list by default with support for custom wordlists.

478.9k](/packages/nicobleiler-php-passphrase)[minvws/horsebattery

A password generator inspired by https://xkcd.com/936/

11101.9k1](/packages/minvws-horsebattery)

PHPackages © 2026

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