Generate secure random strings (passwords / salts)

1.3.0 2016-04-08 21:33 UTC


Latest Stable Version Total Downloads Author License Build Status

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

Like this project? Keep me caffeinated by making a donation.

Install with Composer

composer require phlak/strgen

Example Usage

// Import StrGen
use StrGen;

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

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

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 an array of set names to the StrGen class:

Example using built-in sets:

$generator = new StrGen\Generator(['lower', 'upper', 'numeric']);

Available presets:

Key Character Set
lower abcdefghijklmnopqrstuvwxyz
numeric 0123456789
special !@#$%^&*()-_=+.?
extra {}[]<>:;/\|~

Custom sets:

You can also manually define a character set by passing a string of characters to the StrGen class:

$generator = new StrGen\Generator('0123456789abcdef');


Please report bugs to the GitHub Issue Tracker.


This project is liscensed under the MIT License.