PHPackages                             phlak/strgen - 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. phlak/strgen

ActiveLibrary

phlak/strgen
============

Generate secure random strings (e.g. passwords / salts)

3.0.0(8y ago)2342.8k↓35.7%6[1 PRs](https://github.com/PHLAK/StrGen/pulls)6MITPHPPHP &gt;=5.6

Since May 5Pushed 2y ago2 watchersCompare

[ Source](https://github.com/PHLAK/StrGen)[ Packagist](https://packagist.org/packages/phlak/strgen)[ RSS](/packages/phlak-strgen/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (11)Used By (6)

 [![StrGen](strgen.png)](strgen.png)

 [![Join the Community](https://camo.githubusercontent.com/073a08ec4c3c801a8e24c53184d95a6562d74582854cb46320bcd76ef48ea543/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4a6f696e5f7468652d436f6d6d756e6974792d3762313666662e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/PHLAK/StrGen/discussions) [![Become a Sponsor](https://camo.githubusercontent.com/00da07edf5fbff7528a4743d85563603f9284f02680e0ab1e73652e680878548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4265636f6d655f612d53706f6e736f722d6363343139352e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/users/PHLAK/sponsorship) [![One-time Donation](https://camo.githubusercontent.com/e9b5aa71ffdb17943c10c6d6b4a3132b66a938495331e488ecbdad1f3c078879/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d616b655f612d446f6e6174696f6e2d3030366262362e7376673f7374796c653d666f722d7468652d6261646765)](https://paypal.me/ChrisKankiewicz)
 [![Latest Stable Version](https://camo.githubusercontent.com/06b1e4e7df31d4900c8c74ebdc534debaa729061b7dd9db614657ab05bfe0b7d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70686c616b2f73747267656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phlak/strgen) [![Total Downloads](https://camo.githubusercontent.com/e303592164c4eaa611d92e5c49bebf6f0c831ed220c69ad38e27f4a467a12279/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70686c616b2f73747267656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phlak/strgen) [![License](https://camo.githubusercontent.com/102a54876f2fd693363ceadac4016b1b3b360bf046ebd0c8b1e1734a639065b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f70686c616b2f73747267656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phlak/strgen) [![](https://camo.githubusercontent.com/843b69985feeb535eedd61e01758d887e8c13bc20d4788f14a0ca63a2e8abec0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636865636b732d7374617475732f50484c414b2f53747247656e2f6d61737465723f7374796c653d666c61742d737175617265)](https://github.com/PHLAK/StrGen/actions)

 PHP library for simple secure random string generation (e.g. - passwords / salts)
 Created by [Chris Kankiewicz](https://www.ChrisKankiewicz.com) ([@PHLAK](https://twitter.com/PHLAK))

---

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

[](#requirements)

- [PHP](https://php.net) &gt;= 7.2

Install with Composer
---------------------

[](#install-with-composer)

```
composer require phlak/strgen
```

Usage
-----

[](#usage)

```
// Import StrGen
use PHLAK\StrGen;

// Initialize the Generator
$generator = new StrGen\Generator();

// Generate a random string of characters
$generator->length(16)->generate(); // Returns something like '8a*Ag@I0*s0v[S3u'
```

### Character Sets

[](#character-sets)

StrGen has a few built-in character sets available for ease of use. You can specify which set(s) to use by passing a character set or an array of sets to the `charset()` method.

**Example using built-in sets:**

```
$generator = new StrGen\Generator();

$generator->charset(StrGen\CharSet::ALPHA_NUMERIC)->generate();

// or

$generator->charset([StrGen\CharSet::MIXED_ALPHA, StrGen\CharSet::NUMERIC])->generate();
```

**Available presets:**

KeyCharacter Set`StrGen\CharSet::LOWER_ALPHA``abcdefghijklmnopqrstuvwxyz``StrGen\CharSet::UPPER_ALPHA``ABCDEFGHIJKLMNOPQRSTUVWXYZ``StrGen\CharSet::MIXED_ALPHA``abcdefghijklmnopqrstuvwxyz`
`ABCDEFGHIJKLMNOPQRSTUVWXYZ``StrGen\CharSet::NUMERIC``0123456789``StrGen\CharSet::ALPHA_NUMERIC``abcdefghijklmnopqrstuvwxyz`
`ABCDEFGHIJKLMNOPQRSTUVWXYZ`
`0123456789``StrGen\CharSet::SPECIAL``!@#$%^&*()-_=+.?{}[]:;/\|~``StrGen\CharSet::ALL``abcdefghijklmnopqrstuvwxyz`
`ABCDEFGHIJKLMNOPQRSTUVWXYZ`
`0123456789`
`!@#$%^&*()-_=+.?{}[]:;/\|~`**Custom sets:**

You can also manually define a character set by passing a string of characters to the `charset()` method.

```
$generator = new StrGen\Generator();

$generator->charset('0123456789abcdef')->generate();
```

### Convenience Functions

[](#convenience-functions)

StrGen also has built-in convenience functions for generating strings from the included character sets or a custom character set.

```
$generator->lowerAlpha($length);
$generator->upperAlpha($length);
$generator->mixedAlpha($length);
$generator->numeric($length);
$generator->alphaNumeric($length);
$generator->special($length);
$generator->all($length);
$generator->custom($length, $charset);
```

Changelog
---------

[](#changelog)

A list of changes can be found on the [GitHub Releases](https://github.com/PHLAK/StrGen/releases) page.

Troubleshooting
---------------

[](#troubleshooting)

For general help and support join our [Spectrum community](https://spectrum.chat/phlaknet).

Please report bugs to the [GitHub Issue Tracker](https://github.com/PHLAK/StrGen/issues).

Copyright
---------

[](#copyright)

This project is licensed under the [MIT License](https://github.com/PHLAK/StrGen/blob/master/LICENSE).

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 96% 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 ~194 days

Recently: every ~164 days

Total

8

Last Release

3036d ago

Major Versions

1.4.1 → 2.0.02017-09-06

2.0.0 → 3.0.02018-01-25

PHP version history (4 changes)1.0.0PHP &gt;=5.3.0

1.2.0PHP &gt;=5.5.0

1.3.0PHP &gt;=5.4.0

1.4.0PHP &gt;=5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53531?v=4)[Chris Kankiewicz](/maintainers/PHLAK)[@PHLAK](https://github.com/PHLAK)

---

Top Contributors

[![PHLAK](https://avatars.githubusercontent.com/u/53531?v=4)](https://github.com/PHLAK "PHLAK (95 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![alfredbez](https://avatars.githubusercontent.com/u/1001186?v=4)](https://github.com/alfredbez "alfredbez (1 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")

---

Tags

phpphp-libraryrandom-stringstringpasswordgenerationsalt

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/phlak-strgen/health.svg)

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

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[symfony/string

Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way

1.8k724.1M827](/packages/symfony-string)[ircmaxell/password-compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password\_hash

2.1k56.8M122](/packages/ircmaxell-password-compat)[symfony/password-hasher

Provides password hashing utilities

814137.2M91](/packages/symfony-password-hasher)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

87117.5M63](/packages/bjeavons-zxcvbn-php)[twig/string-extra

A Twig extension for Symfony String

22046.0M133](/packages/twig-string-extra)

PHPackages © 2026

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