]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/crypto/class_CryptoHelper.php
Added the ability to create hashes without the fixed (extra) salt
[core.git] / inc / classes / main / crypto / class_CryptoHelper.php
index 61df314948539b8df5a9d01658b16b14b409ab46..52bd668a9f9d83d314fb65234d78fd90ca09fd39 100644 (file)
@@ -140,9 +140,10 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
         *
         * @param       $str            Unhashed string
         * @param       $oldHash        A hash from previous hashed string
         *
         * @param       $str            Unhashed string
         * @param       $oldHash        A hash from previous hashed string
+        * @param       $withFixed      Whether to include a fixed salt (not recommended in p2p applications)
         * @return      $hashed         The hashed and salted string
         */
         * @return      $hashed         The hashed and salted string
         */
-       public function hashString ($str, $oldHash = '') {
+       public function hashString ($str, $oldHash = '', $withFixed = true) {
                // Cast the string
                $str = (string) $str;
 
                // Cast the string
                $str = (string) $str;
 
@@ -160,11 +161,20 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
 
                // Hash the password with salt
                //* DEBUG: */ echo "salt=".$salt."/plain=".$str."<br />\n";
 
                // Hash the password with salt
                //* DEBUG: */ echo "salt=".$salt."/plain=".$str."<br />\n";
-               $hashed = $salt . md5(sprintf($this->getConfigInstance()->getConfigEntry('hash_mask'),
-                       $salt,
-                       $this->getRngInstance()->getFixedSalt(),
-                       $str
-               ));
+               if ($withFixed === true) {
+                       // Use additional fixed salt
+                       $hashed = $salt . md5(sprintf($this->getConfigInstance()->getConfigEntry('hash_salt_mask'),
+                               $salt,
+                               $this->getRngInstance()->getFixedSalt(),
+                               $str
+                       ));
+               } else {
+                       // Use salt+string to hash
+                       $hashed = $salt . md5(sprintf($this->getConfigInstance()->getConfigEntry('hash_normal_mask'),
+                               $salt,
+                               $str
+                       ));
+               }
 
                // And return it
                return $hashed;
 
                // And return it
                return $hashed;