Better random string generation.
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 30 Jul 2010 07:47:44 +0000 (01:47 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 30 Jul 2010 08:54:10 +0000 (02:54 -0600)
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).

51 files changed:
ansel/lib/Ansel.php
ansel/xppublish.php
fima/lib/Driver/sql.php
fima/lib/Forms/CreateLedger.php
folks/lib/Friends/shared.php
framework/Block/lib/Horde/Block/Layout/Manager.php
framework/Core/lib/Horde/Config.php
framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php
framework/Core/package.xml
framework/Model/lib/Horde/Form/VarRenderer/Xhtml.php
framework/Prefs/lib/Horde/Prefs/Identity.php
framework/Rpc/lib/Horde/Rpc/Webdav.php
framework/Secret/lib/Horde/Secret.php
framework/SyncML/SyncML/Backend/Sql.php
framework/SyncML/package.xml
framework/Token/lib/Horde/Token.php
framework/Util/lib/Horde/Util.php
framework/iCalendar/iCalendar/vevent.php
framework/iCalendar/package.xml
gollem/lib/Api.php
gollem/selectlist.php
horde/admin/alarms.php
horde/templates/contents/open_view_win.js
hylax/lib/Driver/spandsp.php
imp/attachment.php
imp/lib/Compose.php
imp/lib/Injector/Binder/Imaptree.php
ingo/config/backends.php.dist
kronolith/lib/Driver/Sql.php
kronolith/lib/Kronolith.php
kronolith/lib/Resource.php
mnemo/lib/Driver.php
mnemo/lib/Driver/kolab.php
mnemo/lib/Driver/sql.php
mnemo/lib/Forms/CreateNotepad.php
nag/lib/Driver.php
nag/lib/Driver/Kolab.php
nag/lib/Driver/Sql.php
nag/lib/Nag.php
skoli/lib/Driver.php
skoli/lib/Driver/sql.php
skoli/lib/Forms/CreateClass.php
trean/lib/Bookmarks.php
turba/lib/Driver.php
turba/lib/Driver/Kolab.php
turba/lib/Driver/Sql.php
turba/scripts/upgrades/public_to_horde_share.php
turba/search.php
whups/lib/Query.php
whups/lib/View/Results.php
wicked/scripts/mail-filter.php

index f1acedb..fa0dc15 100644 (file)
@@ -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'];
index 7bc9a5a..975b63d 100644 (file)
@@ -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");
index 9524b8a..23dc94f 100644 (file)
@@ -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, ' .
index dbdd60e..ad50492 100644 (file)
@@ -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;
         }
index 0002a98..f7165e3 100644 (file)
@@ -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();
     }
index 6021335..d42bc9f 100644 (file)
@@ -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)));
         }
     }
 
index 6c93060..a01d1b9 100644 (file)
@@ -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:
index 2c36973..034b074 100644 (file)
@@ -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 = '
             <script type="text/javascript">
             var obrowserWindowName;
index 301d4dc..ea38702 100644 (file)
@@ -290,6 +290,10 @@ Application Framework.</description>
     <channel>pear.horde.org</channel>
    </package>
    <package>
+    <name>Support</name>
+    <channel>pear.horde.org</channel>
+   </package>
+   <package>
     <name>Url</name>
     <channel>pear.horde.org</channel>
    </package>
index 9db8f92..3195826 100644 (file)
@@ -728,7 +728,7 @@ EOT;
     {
         $varname = $var->getVarName();
         $varvalue = $vars->get($varname);
-        $fieldId = 'obrowser_' . hash('md5', uniqid(rand(), true));
+        $fieldId = 'obrowser_' . uniqid(mt_rand());
         $html = '
             <script type="text/javascript">
             var obrowserWindowName;
index feb49f4..90475d1 100644 (file)
@@ -402,7 +402,7 @@ class Horde_Prefs_Identity
     {
         global $conf;
 
-        $hash = base_convert(microtime() . mt_rand(), 10, 36);
+        $hash = base_convert(strval(new Horde_Support_Uuid()), 10, 36);
 
         $pref = @unserialize($this->_prefs->getValue('confirm_email', false));
         $pref = $pref
index fed5be8..a9f533d 100644 (file)
@@ -1844,7 +1844,7 @@ class Horde_Rpc_Webdav extends Horde_Rpc
 
                 // a little naive, this sequence *might* be part of the content
                 // but it's really not likely and rather expensive to check
-                $this->multipart_separator = "SEPARATOR_".md5(microtime());
+                $this->multipart_separator = "SEPARATOR_" . uniqid(mt_rand());
 
                 // generate HTTP header
                 header("Content-type: multipart/byteranges; boundary=".$this->multipart_separator);
index 41f400a..4cfc3e2 100644 (file)
@@ -145,7 +145,7 @@ class Horde_Secret
                 $key = $_COOKIE[$keyname . '_key'];
                 $set = false;
             } else {
-                $key = $_COOKIE[$keyname . '_key'] = hash('md5', uniqid());
+                $key = $_COOKIE[$keyname . '_key'] = uniqid(mt_rand());
             }
         } else {
             $key = session_id();
index f190a7f..9270050 100644 (file)
@@ -305,7 +305,7 @@ class SyncML_Backend_Sql extends SyncML_Backend {
 
         // Generate an id (suid). It's also possible to use a database
         // generated primary key here.
-        $suid = $this->_generateID();
+        $suid = strval(new Horde_Support_Uuid());
         $created_ts = $this->getCurrentTimeStamp();
 
         $r = $this->_db->exec(
@@ -803,25 +803,6 @@ class SyncML_Backend_Sql extends SyncML_Backend {
     }
 
     /**
-     * Generates a unique ID used as suid
-     *
-     * @return string  A unique ID.
-     */
-    function _generateID()
-    {
-        return date('YmdHis') . '.'
-            . substr(str_pad(base_convert(microtime(), 10, 36),
-                             16,
-                             uniqid(mt_rand()),
-                             STR_PAD_LEFT),
-                     -16)
-            . '@'
-            . (!empty($_SERVER['SERVER_NAME'])
-               ? $_SERVER['SERVER_NAME']
-               : 'localhost');
-    }
-
-    /**
      * Checks if the parameter is a PEAR_Error object and if so logs the
      * error.
      *
@@ -1040,7 +1021,7 @@ class SyncML_Backend_Sql extends SyncML_Backend {
 
         // Generate an id (suid). It's also possible to use a database
         // generated primary key here. */
-        $suid = $this->_generateID();
+        $suid = strval(new Horde_Support_Uuid());
 
         $created_ts = $this->getCurrentTimeStamp();
         $r = $this->_db->exec(
index b76c516..b6cfdbc 100644 (file)
@@ -85,6 +85,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
     <min>1.4.0b1</min>
    </pearinstaller>
    <package>
+    <name>Support</name>
+    <channel>pear.horde.org</channel>
+   </package>
+   <package>
     <name>XML_WBXML</name>
     <channel>pear.horde.org</channel>
    </package>
index 85df078..9fd829d 100644 (file)
@@ -57,7 +57,7 @@ class Horde_Token
      */
     static public function generateId($seed = '')
     {
-        return Horde_Url::uriB64Encode(pack('H*', sha1(uniqid(mt_rand(), true) . $seed . (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''))));
+        return Horde_Url::uriB64Encode(pack('H*', hash('sha1', uniqid(mt_rand()) . $seed . (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''))));
     }
 
 }
index a4a48c6..1606cd5 100644 (file)
@@ -440,7 +440,7 @@ class Horde_Util
         /* Get the first 8 characters of a random string to use as a temporary
            directory name. */
         do {
-            $new_dir = $temp_dir . '/' . substr(base_convert(mt_rand() . microtime(), 10, 36), 0, 8);
+            $new_dir = $temp_dir . '/' . substr(base_convert(uniqid(mt_rand()), 10, 36), 0, 8);
         } while (file_exists($new_dir));
 
         $old_umask = umask(0000);
index b1c4bbf..3043c82 100644 (file)
@@ -24,9 +24,7 @@ class Horde_iCalendar_vevent extends Horde_iCalendar {
         // Default values.
         $requiredAttributes = array();
         $requiredAttributes['DTSTAMP'] = time();
-        $requiredAttributes['UID'] = $this->_exportDateTime(time())
-            . substr(str_pad(base_convert(microtime(), 10, 36), 16, uniqid(mt_rand()), STR_PAD_LEFT), -16)
-            . '@' . (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost');
+        $requiredAttributes['UID'] = strval(new Horde_Support_Uuid());
 
         $method = !empty($this->_container) ?
             $this->_container->getAttribute('METHOD') : 'PUBLISH';
index edda95d..dd19af5 100644 (file)
@@ -109,6 +109,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
     <channel>pear.horde.org</channel>
    </package>
    <package>
+    <name>Support</name>
+    <channel>pear.horde.org</channel>
+   </package>
+   <package>
     <name>Util</name>
     <channel>pear.horde.org</channel>
    </package>
index 7e76b35..b5c3abe 100644 (file)
@@ -478,7 +478,7 @@ class Gollem_Api extends Horde_Registry_Api
     public function setSelectlist($selectid = '', $files = array())
     {
         if (empty($selectid)) {
-            $selectid = uniqid(mt_rand(), true);
+            $selectid = uniqid(mt_rand());
         }
 
         if (count($files) > 0) {
index e97d3c2..e42af75 100644 (file)
@@ -20,7 +20,7 @@ $currdir = Gollem::getDir();
 /* Create a new cache ID if one does not already exist. */
 $cacheid = Horde_Util::getFormData('cacheid');
 if (empty($cacheid)) {
-    $cacheid = uniqid(mt_rand(), true);
+    $cacheid = uniqid(mt_rand());
     $_SESSION['gollem']['selectlist'][$cacheid] = array();
 }
 
index a6f50e2..b3219f2 100644 (file)
@@ -40,9 +40,7 @@ foreach ($horde_alarm->handlers() as $name => $method) {
 if ($form->validate()) {
     $form->getInfo($vars, $info);
     if (empty($info['alarm'])) {
-        $info['alarm'] = date('YmdHis') . '.'
-            . substr(str_pad(base_convert(microtime(), 10, 36), 16, uniqid(mt_rand()), STR_PAD_LEFT), -16)
-            . '@' . $GLOBALS['conf']['server']['name'];
+        $info['alarm'] = strval(new Horde_Support_Uuid());
     }
 
     $params = array();
index e0b4eb5..a421c57 100644 (file)
@@ -20,7 +20,7 @@ function tr(badval)
 function view(url, partid)
 {
     param = "menubar=yes,toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes";
-    window.open(url, '<?php echo base_convert(microtime(), 10, 36) ?>' + tr(partid), param);
+    window.open(url, '<?php echo uniqid() ?>' + tr(partid), param);
 }
 
 // -->
index 842b9d2..a0fbbb4 100644 (file)
@@ -47,7 +47,7 @@ class Hylax_Driver_spandsp extends Hylax_Driver {
         $data .= sprintf("Application: %s\n", 'txfax');
         $data .= sprintf("Data: %s|caller\n", $filename);
 
-        $outfile = sprintf("%s/%s.call", $conf['fax']['params']['outgoing'], md5(microtime()));
+        $outfile = sprintf("%s/%s.call", $conf['fax']['params']['outgoing'], strval(new Horde_Support_Uuid()));
         if ($fh = fopen($outfile, "w")) {
             fwrite($fh, $data);
             fclose($fh);
index 4448955..af290d8 100644 (file)
@@ -67,7 +67,7 @@ if ($conf['compose']['link_attachments_notify']) {
         }
     } else {
         /* Create a random identifier for this file. */
-        $id = uniqid(mt_rand());
+        $id = strval(new Horde_Support_Uuid());
         try {
             $vfsroot->writeData($full_path, $file_name . '.notify', $id, true);
 
index f03b680..6ac3d0f 100644 (file)
@@ -1943,7 +1943,7 @@ class IMP_Compose
         if ($GLOBALS['conf']['compose']['use_vfs']) {
             try {
                 $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs();
-                $cacheID = uniqid(mt_rand());
+                $cacheID = strval(new Horde_Support_Uuid());
 
                 if ($vfs_file) {
                     $vfs->write(self::VFS_ATTACH_PATH, $cacheID, $data, true);
index db0ab5b..6948da0 100644 (file)
@@ -25,7 +25,7 @@ class IMP_Injector_Binder_Imaptree implements Horde_Injector_Binder
 
         if (empty($_SESSION['imp']['cache']['tree'])) {
             if (!($cache instanceof Horde_Cache_Null)) {
-                $_SESSION['imp']['cache']['tree'] = uniqid(mt_rand() . $GLOBALS['registry']->getAuth());
+                $_SESSION['imp']['cache']['tree'] = strval(new Horde_Support_Uuid());
             }
         } else {
             $instance = @unserialize($cache->get($_SESSION['imp']['cache']['tree'], 86400));
index 5b2702c..4306b92 100644 (file)
@@ -241,7 +241,7 @@ $backends['sivtest'] = array(
         'command' => '/usr/bin/sivtest',
         // name of the socket we're using
         'socket' => Horde::getTempDir() . '/sivtest.'
-            . md5(uniqid(rand())) . '.sock',
+            . uniqid(mt_rand()) . '.sock',
     ),
     'script' => 'sieve',
     'scriptparams' => array(),
index 5d0a078..ead9b6a 100644 (file)
@@ -607,7 +607,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
         if ($event->id) {
             $id = $event->id;
         } else {
-            $id = hash('md5', uniqid(mt_rand(), true));
+            $id = strval(new Horde_Support_Uuid);
             $event->id = $id;
         }
 
index 0056a26..0494eeb 100644 (file)
@@ -1561,7 +1561,7 @@ class Kronolith
     public static function addShare($info)
     {
         try {
-            $calendar = $GLOBALS['kronolith_shares']->newShare(hash('md5', microtime()));
+            $calendar = $GLOBALS['kronolith_shares']->newShare(strval(new Horde_String_Uuid()));
         } catch (Horde_Share_Exception $e) {
             throw new Kronolith_Exception($e);
         }
index ea1c4b6..0199461 100644 (file)
@@ -34,7 +34,7 @@ class Kronolith_Resource
     static public function addResource($resource)
     {
         // Create a new calendar id.
-        $calendar = 'resource_' . hash('md5', microtime());
+        $calendar = 'resource_' . uniqid(mt_rand());
         $resource->set('calendar', $calendar);
         $driver = Kronolith::getDriver('Resource');
 
@@ -57,4 +57,4 @@ class Kronolith_Resource
         return false;
     }
 
-}
\ No newline at end of file
+}
index e81df7e..524bc2d 100644 (file)
@@ -68,20 +68,6 @@ class Mnemo_Driver {
     }
 
     /**
-     * Generate a universal / unique identifier for a task. This is
-     * NOT something that we expect to be able to parse into a
-     * tasklist and a taskId.
-     *
-     * @return string  A nice unique string (should be 255 chars or less).
-     */
-    function generateUID()
-    {
-        return date('YmdHis') . '.'
-            . substr(str_pad(base_convert(microtime(), 10, 36), 16, uniqid(mt_rand()), STR_PAD_LEFT), -16)
-            . '@' . $GLOBALS['conf']['server']['name'];
-    }
-
-    /**
      * Update the description (short summary) of a memo.
      *
      * @param integer $memo_id  The memo to update.
index 643f333..aa88ae6 100644 (file)
@@ -351,7 +351,7 @@ class Mnemo_Driver_kolab_wrapper_old extends Mnemo_Driver_kolab_wrapper {
         if (isset($uid)) {
             $result = $this->_kolab->loadObject($uid);
         } else {
-            $uid = md5(uniqid(mt_rand(), true));
+            $uid = strval(new Horde_Support_Uuid());
             $result = $this->_kolab->newObject($uid);
         }
         if (is_a($result, 'PEAR_Error')) {
@@ -594,7 +594,7 @@ class Mnemo_Driver_kolab_wrapper_new extends Mnemo_Driver_kolab_wrapper {
     function _setObject($desc, $body, $category = '', $uid = null, $passphrase = null)
     {
         if (empty($uid)) {
-            $note_uid = $this->_store->generateUID();
+            $note_uid = strval(new Horde_Support_Uuid());
             $old_uid = null;
             $action = array('action' => 'add');
         } else {
index f26629a..2cd775b 100644 (file)
@@ -214,7 +214,7 @@ class Mnemo_Driver_sql extends Mnemo_Driver {
      */
     function add($desc, $body, $category = '', $uid = null, $passphrase = null)
     {
-        $noteId = md5(uniqid(mt_rand(), true));
+        $noteId = strval(new Horde_Support_Uuid());
 
         if ($passphrase) {
             $body = $this->encrypt($body, $passphrase);
@@ -225,7 +225,7 @@ class Mnemo_Driver_sql extends Mnemo_Driver {
         }
 
         if (is_null($uid)) {
-            $uid = $this->generateUID();
+            $uid = strval(new Horde_Support_Uuid());
         }
 
         $query = 'INSERT INTO ' . $this->_params['table'] .
@@ -429,7 +429,7 @@ class Mnemo_Driver_sql extends Mnemo_Driver {
     {
         /* Make sure notes always have a UID. */
         if (empty($row['memo_uid'])) {
-            $row['memo_uid'] = $this->generateUID();
+            $row['memo_uid'] = strval(new Horde_Support_Uuid());
 
             $query = 'UPDATE ' . $this->_params['table'] .
                 ' SET memo_uid = ?' .
index 79e164b..8c48a50 100644 (file)
@@ -40,7 +40,7 @@ class Mnemo_CreateNotepadForm extends Horde_Form {
     {
         // Create new share.
         try {
-            $notepad = $GLOBALS['mnemo_shares']->newShare(md5(microtime()));
+            $notepad = $GLOBALS['mnemo_shares']->newShare(strval(new Horde_Support_Uuid()));
         } catch (Horde_Share_Exception $e) {
             Horde::logMessage($e->getMessage(), 'ERR');
             throw new Mnemo_Exception($e);
index 69dfc0f..5e77311 100644 (file)
@@ -83,20 +83,6 @@ class Nag_Driver
     }
 
     /**
-     * Generate a universal / unique identifier for a task. This is
-     * NOT something that we expect to be able to parse into a
-     * tasklist and a taskId.
-     *
-     * @return string  A nice unique string (should be 255 chars or less).
-     */
-    function generateUID()
-    {
-        return date('YmdHis') . '.'
-            . substr(str_pad(base_convert(microtime(), 10, 36), 16, uniqid(mt_rand()), STR_PAD_LEFT), -16)
-            . '@' . $GLOBALS['conf']['server']['name'];
-    }
-
-    /**
      * Attempts to return a concrete Nag_Driver instance based on $driver.
      *
      * @param string    $tasklist   The name of the tasklist to load.
@@ -211,7 +197,7 @@ class Nag_Driver
                  $owner = null, $assignee = null)
     {
         if (is_null($uid)) {
-            $uid = $this->generateUID();
+            $uid = strval(new Horde_Support_Uuid());
         }
         if (is_null($owner)) {
             $owner = $GLOBALS['registry']->getAuth();
index d6bcd28..035419b 100644 (file)
@@ -436,7 +436,7 @@ class Nag_Driver_kolab_wrapper_old extends Nag_Driver_kolab_wrapper {
     {
         // Usually provided by the generic Driver class
         if ($uid !== null) {
-            $uid = $this->generateUID();
+            $uid = strval(new Horde_Support_Uuid());
         }
 
         // Load the object into the kolab driver
@@ -785,7 +785,7 @@ class Nag_Driver_kolab_wrapper_new extends Nag_Driver_kolab_wrapper {
                         $completed_date = null)
     {
         if (empty($uid)) {
-            $task_uid = $this->_store->generateUID();
+            $task_uid = strval(new Horde_Support_Uuid());
             $old_uid = null;
         } else {
             list($task_uid, $tasklist) = $this->_splitId($uid);
index 6a1f230..b0f1185 100644 (file)
@@ -162,9 +162,9 @@ class Nag_Driver_Sql extends Nag_Driver {
                   $methods = null, $uid = null, $parent = '', $private = false,
                   $owner = null, $assignee = null)
     {
-        $taskId = md5(uniqid(mt_rand(), true));
+        $taskId = strval(new Horde_Support_Uuid());
         if ($uid === null) {
-            $uid = $this->generateUID();
+            $uid = strval(new Horde_Support_Uuid());
         }
 
         $query = sprintf(
@@ -528,7 +528,7 @@ class Nag_Driver_Sql extends Nag_Driver {
     {
         /* Make sure tasks always have a UID. */
         if (empty($row['task_uid'])) {
-            $row['task_uid'] = $this->generateUID();
+            $row['task_uid'] = strval(new Horde_Support_Uuid());
 
             $query = 'UPDATE ' . $this->_params['table'] .
                 ' SET task_uid = ?' .
index de89b72..67b247a 100644 (file)
@@ -445,7 +445,7 @@ class Nag
     public static function addTasklist($info)
     {
         try {
-            $tasklist = $GLOBALS['nag_shares']->newShare(md5(microtime()));
+            $tasklist = $GLOBALS['nag_shares']->newShare(strval(new Horde_Support_Uuid()));
             $tasklist->set('name', $info['name']);
             $tasklist->set('color', $info['color']);
             $tasklist->set('desc', $info['description']);
index 697f4d0..279f9b9 100644 (file)
@@ -135,17 +135,4 @@ class Skoli_Driver {
         return $instances[$signature];
     }
 
-    /**
-     * Generate a universal / unique identifier for an entry. This is
-     * NOT something that we expect to be able to parse into a
-     * entry list.
-     *
-     * @return string  A nice unique string (should be 255 chars or less).
-     */
-    function generateUID()
-    {
-        return date('YmdHis') . '.'
-            . substr(str_pad(base_convert(microtime(), 10, 36), 16, uniqid(mt_rand()), STR_PAD_LEFT), -16)
-            . '@' . $GLOBALS['conf']['server']['name'];
-    }
 }
index aa6375c..fb7393f 100644 (file)
@@ -504,9 +504,9 @@ class Skoli_Driver_sql extends Skoli_Driver {
             $query = 'INSERT INTO ' . $this->_params['objects_table'] .
                      ' (object_id, object_owner, object_uid, class_id, student_id, object_time, object_type)' .
                      ' VALUES (?, ?, ?, ?, ?, ?, ?)';
-            $entryId = md5(uniqid(mt_rand(), true));
+            $entryId = strval(new Horde_Support_Uuid());
             $date = new Horde_Date($vars->get('object_time'));
-            $values = array($entryId, $GLOBALS['registry']->getAuth(), $this->generateUID(), $this->_class, $studentid, $date->datestamp(), $vars->get('object_type'));
+            $values = array($entryId, $GLOBALS['registry']->getAuth(), strval(new Horde_Support_Uuid()), $this->_class, $studentid, $date->datestamp(), $vars->get('object_type'));
 
             /* Log the query at a DEBUG log level. */
             Horde::logMessage(sprintf('Skoli_Driver_sql::addEntry(): %s', $query), 'DEBUG');
index 90f10b4..e930a07 100644 (file)
@@ -168,7 +168,7 @@ class Skoli_CreateClassForm extends Horde_Form {
         }
 
         // Create new share.
-        $this->shareid = md5(microtime());
+        $this->shareid = strval(new Horde_Support_Uuid());
         $class = $GLOBALS['skoli_shares']->newShare($this->shareid);
         if (is_a($class, 'PEAR_Error')) {
             return $class;
index ab9032e..1187b17 100644 (file)
@@ -821,7 +821,7 @@ class DataTreeObject_Folder extends DataTreeObject {
      */
     function addFolder($properties)
     {
-        $folder = &$this->_shareOb->newFolder($this->getName() . ':' . md5(uniqid(mt_rand())), $properties);
+        $folder = &$this->_shareOb->newFolder($this->getName() . ':' . strval(new Horde_Support_Uuid()), $properties);
         $this->_shareOb->addFolder($folder);
         return $this->datatree->getId($folder);
     }
index d0823d3..1c59de2 100644 (file)
@@ -789,7 +789,7 @@ class Turba_Driver
         }
 
         if (!isset($attributes['__uid'])) {
-            $attributes['__uid'] = $this->generateUID();
+            $attributes['__uid'] = strval(new Horde_Support_Uuid());
         }
 
         $key = $attributes['__key'] = $this->_makeKey($this->toDriverKeys($attributes));
@@ -959,20 +959,6 @@ class Turba_Driver
     }
 
     /**
-     * Generates a universal/unique identifier for a contact. This is NOT
-     * something that we expect to be able to parse into an addressbook and a
-     * contactId.
-     *
-     * @return string  A nice unique string (should be 255 chars or less).
-     */
-    function generateUID()
-    {
-        return date('YmdHis') . '.'
-            . substr(str_pad(base_convert(microtime(), 10, 36), 16, uniqid(mt_rand()), STR_PAD_LEFT), -16)
-            . '@' . $GLOBALS['conf']['server']['name'];
-    }
-
-    /**
      * Exports a given Turba_Object as an iCalendar vCard.
      *
      * @param Turba_Object $object  Turba_Object.
index 4427bd4..a7d8248 100644 (file)
@@ -151,11 +151,9 @@ class Turba_Driver_Kolab extends Turba_Driver
      */
     function generateUID()
     {
-        if (method_exists($this->_wrapper, 'generateUID')) {
-            return $this->_wrapper->generateUID();
-        } else {
-            return parent::generateUID();
-        }
+        return method_exists($this->_wrapper, 'generateUID')
+            ? $this->_wrapper->generateUID()
+            : strval(new Horde_Support_Uuid());
     }
 
     /**
@@ -1281,7 +1279,7 @@ class Turba_Driver_Kolab_Wrapper_New extends Turba_Driver_Kolab_Wrapper {
         }
 
         do {
-            $key = md5(uniqid(mt_rand(), true));
+            $key = strval(new Horde_Support_Uuid());
         } while(in_array($key, array_keys($this->_contacts_cache)));
 
         return $key;
index 321797d..b23bdfc 100644 (file)
@@ -587,7 +587,7 @@ class Turba_Driver_Sql extends Turba_Driver
      */
     function _makeKey($attributes)
     {
-        return md5(uniqid(mt_rand(), true));
+        return strval(new Horde_Support_Uuid());
     }
 
     /**
index b87bcaf..917ed1e 100755 (executable)
@@ -58,9 +58,9 @@ if (!$sourceKey) {
 }
 
 // Create the new share.
-$owner_uid = md5(microtime());
+$owner_uid = strval(new Horde_Support_Uuid());
 $share = &$turba_shares->newShare($sourceKey . ':' . $owner_uid);
-if (is_a($share, 'PEAR_Error')) {
+if ($share instanceof Horde_Share_Exception) {
     var_dump($share);
     exit;
 }
index 4261e8a..b1c65c7 100644 (file)
@@ -27,7 +27,7 @@ function _createVBook($params)
                                     'criteria' => $params['criteria'])));
 
     try {
-        $share = Turba::createShare(md5(microtime()), $params);
+        $share = Turba::createShare(strval(new Horde_Support_Uuid()), $params);
     } catch (Horde_Share_Exception $e) {
         throw new Turba_Exception($e);
     }
index 5ddf99a..041a888 100644 (file)
@@ -1015,7 +1015,7 @@ class Whups_QueryManager {
             }
         } else {
             // Create a new share for the query.
-            $share = $this->_shareManager->newShare(md5(microtime()));
+            $share = $this->_shareManager->newShare(strval(new Horde_Support_Uuid());
             $share->set('name', $query->name);
             $share->set('slug', $query->slug);
             try {
index 4d297ff..c998912 100755 (executable)
@@ -16,7 +16,7 @@ class Whups_View_Results extends Whups_View {
     function Whups_View_Results($params)
     {
         parent::Whups_View($params);
-        $this->_id = md5(uniqid(mt_rand()));
+        $this->_id = uniqid(mt_rand());
     }
 
     function html()
index 0903d7f..5c310db 100755 (executable)
@@ -99,7 +99,7 @@ if ($message->getType() == 'text/plain') {
 $pageBody .= "\n";
 
 if (is_null($pageName)) {
-    $pageName = "EmailMessage" . ucfirst(md5(uniqid('wicked', true)));
+    $pageName = "EmailMessage" . ucfirst(md5(uniqid('wicked')));
 }
 
 $res = $wicked->newPage($pageName, $pageBody);