Download the PHP package nickjbedford/randomstringgenerator without Composer
On this page you can find all versions of the php package nickjbedford/randomstringgenerator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nickjbedford/randomstringgenerator
More information about nickjbedford/randomstringgenerator
Files in nickjbedford/randomstringgenerator
Package randomstringgenerator
Short Description Provides methods to generate cryptographically strong random strings based on an input alphabet.
License MIT
Homepage https://github.com/nickjbedford/randomstringgenerator
Informations about the package randomstringgenerator
Random String Generator
Generator\RandomStringGenerator
generates cryptographically strong random strings based on a supplied alphabet of characters (such as alphanumeric characters). This is perfect for generating API keys within a set of allowed characters. It can also be used to generate strong passwords.
The class relies on the openssl_pseudo_random_bytes()
function to generate the cryptographically strong random numbers for use in building the random strings.
Usage
To generate a 16-character string using the default 62-character alphanumeric alphabet, the usage is as simple as the following:
To use a different alphabet, such as uppercase hexadecimal characters, and to generate a random string of a different length, these parameters can be passed to the class as follows:
$generator = new RandomStringGenerator(RandomStringGenerator::ALPHABET_HEX_UPPER);
$key = $generator->generate(8);
// string(8) "CF70D24E"
A custom alphabet can be provided in the form of an input string of characters, such as:
$generator = new RandomStringGenerator('abc123');
$key = $generator->generate();
// string(16) "cb2c2a33c2c3a23b"
This is then converted to an array of characters internally. This array can be retrieved using the $generator->alphabet()
function with no argument.