Continued with file-based stacks:
[core.git] / inc / classes / main / class_BaseFrameworkSystem.php
index 0bd390928a913efcbcdedf2d8bd51c4e628172d9..47282b389ad847ce13769c57fce125fb019a8386 100644 (file)
@@ -203,6 +203,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $genericArray = array();
 
+       /**
+        * Length of output from hash()
+        */
+       private static $hashLength = NULL;
+
        /***********************
         * Exception codes.... *
         ***********************/
@@ -2090,19 +2095,37 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
-        * Hashes a given string with a simple but stronger hash function (no salts)
+        * Hashes a given string with a simple but stronger hash function (no salt)
+        * and hex-encode it.
         *
         * @param       $str    The string to be hashed
         * @return      $hash   The hash from string $str
         */
-       public function hashString ($str) {
+       public static final function hash ($str) {
                // Hash given string with (better secure) hasher
-               $hash = mhash(MHASH_SHA256, $str);
+               $hash = bin2hex(mhash(MHASH_SHA256, $str));
 
                // Return it
                return $hash;
        }
 
+       /**
+        * "Getter" for length of hash() output. This will be "cached" to speed up
+        * things.
+        *
+        * @return      $length         Length of hash() output
+        */
+       public static final function getHashLength () {
+               // Is it cashed?
+               if (is_null(self::$hashLength)) {
+                       // No, then hash a string and save its length.
+                       self::$hashLength = strlen(self::hash('abc123'));
+               } // END - if
+
+               // Return it
+               return self::$hashLength;
+       }
+
        /**
         * Checks whether the given number is really a number (only chars 0-9).
         *