chriskacerguis / randomstring
simple class to generate a random string (good for random generated passwords)
Installs: 1 670
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 3.7.14
This package is not auto-updated.
Last update: 2019-11-02 23:08:35 UTC
README
A simple library for creating a random string
Requirments
- PHP 5.4+
Usage
$random = new \chriskacerguis\Randomstring\Randomstring();
/*
Generate a random string of 8 charecters, using alpha numerics.
Result = string(8) "ab86d144"
*/
$str = $random->generate(8);
/*
Generate a random string of 15 charecters, using alpha numerics and special charecters
Result = string(15) "vT-`h9tG1Mt.Sj&"
*/
$str = $random->generate(15, true);
/*
Generate a random string of 13 charecters using alpha numerics, and wrap result with strtoupper()
Result = string(13) "LVFUK0X01HVD0"
*/
$str = $random->generate(13, false, 'strtoupper');
Installation via Composer
-
Install Composer to your project root:
curl -sS https://getcomposer.org/installer | php
-
Add a
composer.json
file to your project:{ "require" { "chriskacerguis/randomstring": "1.0.*" } }
-
Run the Composer installer:
php composer.phar install
A Quick Note About Security
This library is built to be "enough" and fast for most applications (like generating an initial password, however for cryptographically secure applications, you should use the PHP method openssl_random_pseudo_bytes() or some other method that uses a cryptographically strong algorithm.