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. [Utility &amp; Helpers](/categories/utility)
4. /
5. joanfabregat/secure-token-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

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

Generate cryptographically secure alphanumeric tokens in PHP

v1.3(1y ago)0110MITPHPPHP &gt;=8.2

Since Apr 29Pushed 1y 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 1mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

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

[](#secure-token-generator)

[![Latest Stable Version](https://camo.githubusercontent.com/2413362c68c35b51d2dd105944fbd62fb643fd8acf36bdc0e0b2e5507274cd3b/68747470733a2f2f706f7365722e707567782e6f72672f6a6f616e66616272656761742f7365637572652d746f6b656e2d67656e657261746f722f76)](//packagist.org/packages/joanfabregat/secure-token-generator)[![Total Downloads](https://camo.githubusercontent.com/b162c3558ed9ccc92540ea25feab2f7d30b8d0951c6fe82723b3b6877f298a80/68747470733a2f2f706f7365722e707567782e6f72672f6a6f616e66616272656761742f7365637572652d746f6b656e2d67656e657261746f722f646f776e6c6f616473)](//packagist.org/packages/joanfabregat/secure-token-generator)[![Latest Unstable Version](https://camo.githubusercontent.com/ace0092cae7f22538f46924f3b9db06fc830386143e8132143180195db328e7e/68747470733a2f2f706f7365722e707567782e6f72672f6a6f616e66616272656761742f7365637572652d746f6b656e2d67656e657261746f722f762f756e737461626c65)](//packagist.org/packages/joanfabregat/secure-token-generator)[![License](https://camo.githubusercontent.com/4b3dad5a4b89bc48a467b8ca6b0aea2d9838e7d5fa041cde9e69b0a2407bfe18/68747470733a2f2f706f7365722e707567782e6f72672f6a6f616e66616272656761742f7365637572652d746f6b656e2d67656e657261746f722f6c6963656e7365)](//packagist.org/packages/joanfabregat/secure-token-generator)

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

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

[](#installation)

The package is [available on Packagist](https://packagist.org/packages/joanfabregat/secure-token-generator). The recommended way to install the library is through [Composer](http://getcomposer.org):

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

Usage
-----

[](#usage)

```
use JoanFabregat\SecureTokenGenerator\SecureTokenGenerator;

// A simple token
$token = SecureTokenGenerator::generate(16);
echo $token; // will echo a 16 characters long alphanumeric token

// With all the options
$token = SecureTokenGenerator::generate(
    length: 32,
    allowDigits: true, // 1234567890
    allowSpecialChars: true, // !@#$%^&*()_+{}|:"?[];',./
    allowUppercase: true, // ABCDEFGHIJKLMNOPQRSTUVWXYZ
    allowLowercase: true, // abcdefghijklmnopqrstuvwxyz
);
echo $token; // will echo a 32 characters long alphanumeric token with special characters

// An integer token
$token = SecureTokenGenerator::generateInt(6);
echo is_int($token); // will echo true
echo $token; // will echo a 6 digits long integer token (ie. 123456)
```

License
-------

[](#license)

The library is published under the MIT license (see [`LICENSE`](LICENSE) file).

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Total

4

Last Release

725d 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 (13 commits)")

###  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)
```

PHPackages © 2026

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