X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fcrypto%2Fclass_CryptoHelper.php;h=1ccdaae901b0712c8644e6001b8de53598cd050d;hp=6384e0d66f01d68f0bfbba84c92c3a7ef21961a8;hb=29266e780769e83234f586c9e5779e3ebc593264;hpb=07ed05a76919524d23b337a7e274fcf990e7b17d diff --git a/inc/classes/main/crypto/class_CryptoHelper.php b/inc/classes/main/crypto/class_CryptoHelper.php index 6384e0d..1ccdaae 100644 --- a/inc/classes/main/crypto/class_CryptoHelper.php +++ b/inc/classes/main/crypto/class_CryptoHelper.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { // Exception constants @@ -50,12 +50,6 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { // Call parent constructor parent::__construct(__CLASS__); - // Set part description - $this->setObjectDescription("Cryptographical helper"); - - // Create unique ID number - $this->generateUniqueId(); - // Clean up a little $this->removeNumberFormaters(); $this->removeSystemArray(); @@ -136,17 +130,17 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { // Cast the string $str = (string) $str; + // Default is the default salt ;-) + $salt = $this->salt; + // Is the old password set? - if (empty($oldHash)) { - // No, then use the current salt - $salt = $this->salt; - } else { + if (!empty($oldHash)) { // Use the salt from hash, first get length $length = $this->getConfigInstance()->readConfig('salt_length'); // Then extract the X first characters from the hash as our salt $salt = substr($oldHash, 0, $length); - } + } // END - if // Hash the password with salt //* DEBUG: */ echo "salt=".$salt."/plain=".$str."
\n"; @@ -172,7 +166,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); // Get key - if ($this->getConfigInstance()->readConfig('crypt_fixed_salt') == "Y") { + if ($this->getConfigInstance()->readConfig('crypt_fixed_salt') === "Y") { $key = md5($this->rngInstance->getFixedSalt()); } else { $key = md5($this->rngInstance->getExtraSalt()); @@ -185,27 +179,27 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { break; case 1: - $garbageString = md5($this->rngInstance->randomString(10))."|".base64_encode($str)."|".crc32($this->rngInstance->randomString(20)); + $garbageString = crc32($this->rngInstance->randomString(10))."|".base64_encode($str)."|".md5($this->rngInstance->randomString(20)); break; case 2: - $garbageString = sha1($this->rngInstance->randomString(10))."|".base64_encode($str)."|".crc32($this->rngInstance->randomString(20)); + $garbageString = crc32($this->rngInstance->randomString(10))."|".base64_encode($str)."|".sha1($this->rngInstance->randomString(20)); break; case 3: - $garbageString = crc32($this->rngInstance->randomString(10))."|".base64_encode($str)."|".md5($this->rngInstance->randomString(20)); + $garbageString = md5($this->rngInstance->randomString(10))."|".base64_encode($str)."|".crc32($this->rngInstance->randomString(20)); break; case 4: - $garbageString = crc32($this->rngInstance->randomString(10))."|".base64_encode($str)."|".sha1($this->rngInstance->randomString(20)); + $garbageString = md5($this->rngInstance->randomString(10))."|".base64_encode($str)."|".md5($this->rngInstance->randomString(20)); break; case 5: - $garbageString = md5($this->rngInstance->randomString(10))."|".base64_encode($str)."|".md5($this->rngInstance->randomString(20)); + $garbageString = md5($this->rngInstance->randomString(10))."|".base64_encode($str)."|".sha1($this->rngInstance->randomString(20)); break; case 6: - $garbageString = md5($this->rngInstance->randomString(10))."|".base64_encode($str)."|".sha1($this->rngInstance->randomString(20)); + $garbageString = sha1($this->rngInstance->randomString(10))."|".base64_encode($str)."|".crc32($this->rngInstance->randomString(20)); break; case 7: @@ -236,7 +230,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); // Get key - if ($this->getConfigInstance()->readConfig('crypt_fixed_salt') == "Y") { + if ($this->getConfigInstance()->readConfig('crypt_fixed_salt') === "Y") { $key = md5($this->rngInstance->getFixedSalt()); } else { $key = md5($this->rngInstance->getExtraSalt()); @@ -247,6 +241,11 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { // Get the real string out $strArray = explode("|", $garbageString); + + // Does the element count match? + assert(count($strArray) == 3); + + // Decode the string $str = base64_decode($strArray[1]); // Trim trailing nulls away