diff --git a/lib/shop.lib.php b/lib/shop.lib.php index 9eed841b5..ed8bad9be 100644 --- a/lib/shop.lib.php +++ b/lib/shop.lib.php @@ -1632,17 +1632,32 @@ function get_coupon_id() { $len = 16; $chars = "ABCDEFGHJKLMNPQRSTUVWXYZ123456789"; - - srand((double)microtime()*1000000); - - $i = 0; + $chars_len = strlen($chars); $str = ''; - while ($i < $len) { - $num = rand() % strlen($chars); - $tmp = substr($chars, $num, 1); - $str .= $tmp; - $i++; + if (function_exists('get_random_token_string')) { + // 문자 종류 수로 나누어 떨어지는 구간만 사용하여 특정 문자에 치우치지 않도록 한다. + $limit = 256 - (256 % $chars_len); + $round = 0; + + while (strlen($str) < $len && $round < 8) { + $bytes = pack('H*', get_random_token_string($len + 8)); + $bytes_len = strlen($bytes); + + for ($i = 0; $i < $bytes_len && strlen($str) < $len; $i++) { + $num = ord($bytes[$i]); + if ($num >= $limit) + continue; + + $str .= substr($chars, $num % $chars_len, 1); + } + + $round++; + } + } + + while (strlen($str) < $len) { + $str .= substr($chars, mt_rand(0, $chars_len - 1), 1); } $str = preg_replace("/([0-9A-Z]{4})([0-9A-Z]{4})([0-9A-Z]{4})([0-9A-Z]{4})/", "\\1-\\2-\\3-\\4", $str); diff --git a/plugin/lgxpay/lgdacom/XPayClient.php b/plugin/lgxpay/lgdacom/XPayClient.php index aee6e9ce9..00a93dfab 100644 --- a/plugin/lgxpay/lgdacom/XPayClient.php +++ b/plugin/lgxpay/lgdacom/XPayClient.php @@ -217,7 +217,6 @@ class XPayClient } else { - mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up. $charid = strtoupper(md5(uniqid(rand(), true))); $hyphen = chr(45); //$uuid = chr(123).substr($charid, 0, 8).$hyphen.substr($charid, 8, 4).$hyphen.substr($charid,12, 4).$hyphen.substr($charid,16, 4).$hyphen.substr($charid,20,12).chr(125);