From: Chuck Hagenbuch Date: Tue, 7 Sep 2010 21:20:53 +0000 (-0400) Subject: Get down to a 23-char id. Discard the more_entropy from uniqid since it just comes... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=dd9c409ef39c829957604f14d184dfe0762aa4fa;p=horde.git Get down to a 23-char id. Discard the more_entropy from uniqid since it just comes from the LCG; use mt_rand() instead. In addition, add some bits based on the hostname to help with uniqueness across hosts. --- diff --git a/framework/Support/lib/Horde/Support/Randomid.php b/framework/Support/lib/Horde/Support/Randomid.php index 71c160e16..815e6ebaa 100644 --- a/framework/Support/lib/Horde/Support/Randomid.php +++ b/framework/Support/lib/Horde/Support/Randomid.php @@ -7,13 +7,13 @@ */ /** - * Class for generating a 24-character random ID string. This string uses all + * Class for generating a 23-character random ID string. This string uses all * characters in the class [-_0-9a-zA-Z]. * * * * @@ -31,14 +31,14 @@ class Horde_Support_Randomid * * @var string */ - private $_rid; + private $_id; /** * New random ID. */ public function __construct() { - $this->generate(); + $this->_id = $this->generate(); } /** @@ -46,9 +46,10 @@ class Horde_Support_Randomid */ public function generate() { - // Base64 can have /, +, and = characters. Restrict to URL-safe - // characters. - $this->_rid = str_replace(array('/', '+', '='), array('-', '_', ''), base64_encode(pack('I', mt_rand()) . pack('H*', str_replace('.', '', uniqid('', true)) . dechex(getmypid())))); + // Base64 can have /, +, and = characters. Restrict to URL-safe characters. + return str_replace(array('/', '+', '='), array('-', '_', ''), base64_encode( + pack('II', mt_rand(), crc32(php_uname('n'))) . pack('H*', uniqid() . dechex(getmypid())) + )); } /** @@ -58,7 +59,6 @@ class Horde_Support_Randomid */ public function __toString() { - return $this->_rid; + return $this->_id; } - }