Rewrites
authorRoland Häder <roland@mxchange.org>
Sun, 26 Aug 2012 21:45:10 +0000 (21:45 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 26 Aug 2012 21:45:10 +0000 (21:45 +0000)
- Added method createUuid() which will check if the PECL extension uuid is
  loaded and use that for e.g. more entropy
- RandomNumberGenerator is now singelton (to save memory)
- TODO added

inc/classes/main/commands/web/class_WebResendLinkCommand.php
inc/classes/main/crypto/class_CryptoHelper.php
inc/classes/main/menu/class_BaseMenu.php
inc/classes/main/rng/class_RandomNumberGenerator.php

index 2cd6a82..3757d4b 100644 (file)
@@ -64,6 +64,7 @@ class WebResendLinkCommand extends BaseCommand implements Commandable {
                $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
 
                // Get a RNG instance (Random Number Generator)
+               // @TODO Rewrite this code to make use of generateRandomString() from 'hub' project
                $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
 
                // Generate a pseudo-random string
index aa4ef88..7fc481d 100644 (file)
@@ -123,7 +123,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
         */
        private function generateSalt () {
                // Get a random string from the RNG
-               $randomString = $this->getRngInstance()->randomString();
+               $randomString = $this->getRngInstance()->randomString() . $this->createUuid();
 
                // Get config entry for salt length
                $length = $this->getConfigInstance()->getConfigEntry('salt_length');
@@ -133,6 +133,26 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
        }
 
        /**
+        * Returns a UUID (Universal Unique IDentifier) if PECL extension uuid was
+        * found or an empty string it not.
+        *
+        * @return      $uuid   UUID with leading dash or empty string
+        */
+       public function createUuid () {
+               // Init empty UUID
+               $uuid = '';
+
+               // Is the UUID extension loaded? (see pecl)
+               if ((extension_loaded('uuid')) && (function_exists('uuid_create'))) {
+                       // Then add it as well
+                       $uuid = uuid_create();
+               } // END - if
+
+               // Return it
+               return $uuid;
+       }
+
+       /**
         * Hashes a string with salt and returns the hash. If an old previous hash
         * is supplied the method will use the first X chars of that hash for hashing
         * the password. This is useful if you want to check if password is identical
index 6967211..ffebece 100644 (file)
@@ -47,23 +47,23 @@ class BaseMenu extends BaseFrameworkSystem {
                $this->setTemplateInstance($templateInstance);
 
                // Load the menu template for all
-               $this->getTemplateInstance()->loadMenuTemplate('generic_menu_entries');
+               $templateInstance->loadMenuTemplate('generic_menu_entries');
 
                // Get the 'page' from request instance
                $page = $this->getApplicationInstance()->getRequestInstance()->getRequestElement('page');
 
                // Load the menu template for this page
                try {
-                       $this->getTemplateInstance()->loadMenuTemplate($page . '_menu_entries');
+                       $templateInstance->loadMenuTemplate($page . '_menu_entries');
                } catch (FileIoException $e) {
                        // @TODO Should we log it here? We should, because it will be silently ignored.
                }
 
                // Get the prepared content
-               $menuContent = $this->getTemplateInstance()->getRawTemplateData();
+               $menuContent = $templateInstance->getRawTemplateData();
 
                // Render it here
-               $this->getTemplateInstance()->renderXmlContent($menuContent);
+               $templateInstance->renderXmlContent($menuContent);
                //exit(__METHOD__ . ':!OK');
        }
 
index bc8c42d..6b26fe8 100644 (file)
@@ -48,6 +48,11 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
        private $rndStrLen = 0;
 
        /**
+        * Self instance
+        */
+       private static $selfInstance = NULL;
+
+       /**
         * Protected constructor
         *
         * @param       $className      Name of this class
@@ -65,11 +70,20 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
         * @return      $rngInstance    An instance of this random number generator
         */
        public static final function createRandomNumberGenerator (FrameworkInterface $extraInstance = NULL) {
-               // Get a new instance
-               $rngInstance = new RandomNumberGenerator();
+               // Is self instance set?
+               if (is_null(self::$selfInstance)) {
+                       // Get a new instance
+                       $rngInstance = new RandomNumberGenerator();
 
-               // Initialize the RNG now
-               $rngInstance->initRng($extraInstance);
+                       // Initialize the RNG now
+                       $rngInstance->initRng($extraInstance);
+
+                       // Set it "self"
+                       self::$selfInstance = $rngInstance;
+               } else {
+                       // Use from self instance
+                       $rngInstance = self::$selfInstance;
+               }
 
                // Return the instance
                return $rngInstance;