update generateRndString

This commit is contained in:
printempw 2016-08-18 21:51:39 +08:00
parent 89acfaff8f
commit 1875210f3f

View File

@ -52,12 +52,15 @@ class Utils
/**
* Generate random string
*
* @param int $length
* @param int $length
* @param bool $special_chars
* @return string
*/
public static function generateRndString($length)
public static function generateRndString($length, $special_chars = true)
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
if ($special_chars) $chars .= "!@#$%^&*()-_ []{}<>~`+=,.;:/?|";
$rnd_string = '';
for ($i = 0; $i < $length; $i++) {
$rnd_string .= $chars[mt_rand(0, strlen($chars) - 1)];