From 1875210f3f1b35a69aa059152f68e98cf01f7403 Mon Sep 17 00:00:00 2001 From: printempw Date: Thu, 18 Aug 2016 21:51:39 +0800 Subject: [PATCH] update generateRndString --- app/Services/Utils.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Services/Utils.php b/app/Services/Utils.php index 3fc09994..309b1f3e 100644 --- a/app/Services/Utils.php +++ b/app/Services/Utils.php @@ -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)];