From: Michael M Slusarz Date: Fri, 30 Jul 2010 07:47:44 +0000 (-0600) Subject: Better random string generation. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=79bf8f469ae19a69c1de18c50528aeb89eeef24a;p=horde.git Better random string generation. Use either Horde_Support_Uuid or uniqid(mt_rand()) (the former is more random and should be used for things like persistent data; the latter is useful for things like cache-busting). --- diff --git a/ansel/lib/Ansel.php b/ansel/lib/Ansel.php index f1acedbd9..fa0dc15fd 100644 --- a/ansel/lib/Ansel.php +++ b/ansel/lib/Ansel.php @@ -999,7 +999,7 @@ class Ansel static public function embedCode($options) { if (empty($options['container'])) { - $domid = md5(uniqid()); + $domid = uniqid(); $options['container'] = $domid; } else { $domid = $options['container']; diff --git a/ansel/xppublish.php b/ansel/xppublish.php index 7bc9a5a8f..975b63da8 100644 --- a/ansel/xppublish.php +++ b/ansel/xppublish.php @@ -122,10 +122,10 @@ if ($cmd == 'new') { } catch (Ansel_Exception $e) { $error = sprintf(_("The gallery \"%s\" couldn't be created: %s"), $gallery_name, $e->getMessage()); Horde::logMessage($error, 'ERR'); - } + } } else { if (empty($galleryId) && $prefs->getValue('autoname')) { - $galleryId = md5(microtime()); + $galleryId = strval(new Horde_Support_Uuid()); } if (!$gallery_name) { $gallery_name = _("Untitled"); diff --git a/fima/lib/Driver/sql.php b/fima/lib/Driver/sql.php index 9524b8a44..23dc94ffc 100644 --- a/fima/lib/Driver/sql.php +++ b/fima/lib/Driver/sql.php @@ -520,7 +520,7 @@ class Fima_Driver_sql extends Fima_Driver { */ function _addAccount($number, $type, $name, $eo, $desc, $closed) { - $accountId = md5(uniqid(mt_rand(), true)); + $accountId = strval(new Horde_Support_Uuid()); $query = sprintf( 'INSERT INTO %s (account_id, account_owner, account_number, account_type, ' . @@ -706,7 +706,7 @@ class Fima_Driver_sql extends Fima_Driver { */ function _addPosting($type, $date, $asset, $account, $eo, $amount, $desc) { - $postingId = md5(uniqid(mt_rand(), true)); + $postingId = strval(new Horde_Support_Uuid()); $query = sprintf( 'INSERT INTO %s (posting_id, posting_owner, posting_type, posting_date, ' . diff --git a/fima/lib/Forms/CreateLedger.php b/fima/lib/Forms/CreateLedger.php index dbdd60edf..ad50492a7 100644 --- a/fima/lib/Forms/CreateLedger.php +++ b/fima/lib/Forms/CreateLedger.php @@ -36,7 +36,7 @@ class Fima_CreateLedgerForm extends Horde_Form { function execute() { // Create new share. - $ledger = $GLOBALS['fima_shares']->newShare(md5(microtime())); + $ledger = $GLOBALS['fima_shares']->newShare(strval(new Horde_Support_Uuid())); if (is_a($ledger, 'PEAR_Error')) { return $ledger; } diff --git a/folks/lib/Friends/shared.php b/folks/lib/Friends/shared.php index 0002a982b..f7165e37a 100644 --- a/folks/lib/Friends/shared.php +++ b/folks/lib/Friends/shared.php @@ -145,6 +145,7 @@ class Folks_Friends_shared extends Folks_Friends_sql { * Add group * * @param string $group Group name + * @throws Horde_Share_Exception */ public function addGroup($name) { @@ -159,16 +160,10 @@ class Folks_Friends_shared extends Folks_Friends_sql { $GLOBALS['folks_shares'] = $GLOBALS['injector']->getInstance('Horde_Share')->getScope(); - $share = $GLOBALS['folks_shares']->newShare(hash('md5', microtime())); - if ($share instanceof PEAR_Error) { - return $share; - } + $share = $GLOBALS['folks_shares']->newShare(strval(new Horde_Support_Uuid())); $share->set('name', $name); $result = $GLOBALS['folks_shares']->addShare($share); - if ($result instanceof PEAR_Error) { - return $result; - } return $share->getId(); } diff --git a/framework/Block/lib/Horde/Block/Layout/Manager.php b/framework/Block/lib/Horde/Block/Layout/Manager.php index 60213354e..d42bc9ff0 100644 --- a/framework/Block/lib/Horde/Block/Layout/Manager.php +++ b/framework/Block/lib/Horde/Block/Layout/Manager.php @@ -293,8 +293,8 @@ class Horde_Block_Layout_Manager extends Horde_Block_Layout } if (!empty($url)) { - header('Location: ' . Horde_Util::addParameter($url, 'unique', - md5(microtime()), false)); + $url = new Horde_Url($url); + header('Location: ' . strval($url->unique()->setRaw(true))); } } diff --git a/framework/Core/lib/Horde/Config.php b/framework/Core/lib/Horde/Config.php index 6c93060ba..a01d1b974 100644 --- a/framework/Core/lib/Horde/Config.php +++ b/framework/Core/lib/Horde/Config.php @@ -426,7 +426,7 @@ class Horde_Config switch ($node->tagName) { case 'configdescription': if (empty($name)) { - $name = hash('md5', uniqid(mt_rand(), true)); + $name = uniqid(mt_rand()); } $conf[$name] = array( @@ -437,7 +437,7 @@ class Horde_Config case 'configheader': if (empty($name)) { - $name = hash('md5', uniqid(mt_rand(), true)); + $name = uniqid(mt_rand()); } $conf[$name] = array( @@ -603,7 +603,7 @@ class Horde_Config '_type' => 'text', 'required' => true, 'desc' => $desc, - 'default' => $this->_default($curctx, sha1(uniqid(mt_rand(), true))), + 'default' => $this->_default($curctx, strval(new Horde_Support_Uuid())), 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)) ); break; @@ -625,7 +625,7 @@ class Horde_Config break; case 'configtab': - $key = hash('md5', uniqid(mt_rand(), true)); + $key = uniqid(mt_rand()); $conf[$key] = array( 'tab' => $name, @@ -638,7 +638,7 @@ class Horde_Config break; case 'configplaceholder': - $conf[hash('md5', uniqid(mt_rand(), true))] = 'placeholder'; + $conf[uniqid(mt_rand())] = 'placeholder'; break; default: diff --git a/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php b/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php index 2c36973e7..034b074b2 100644 --- a/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php +++ b/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php @@ -923,7 +923,7 @@ EOT; { $varname = $var->getVarName(); $varvalue = $vars->get($varname); - $fieldId = $this->_genID(md5(uniqid(rand(), true)), false) . 'id'; + $fieldId = $this->_genID(uniqid(mt_rand()), false) . 'id'; $html = '