X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fcrypto%2Fclass_CryptoHelper.php;h=03458ee5f17f138d8f4695978bf57f4669c1d4a5;hb=0ccdb0379f308c6b7b5677b8b7c242df8e9dd300;hp=b8bbbbe258693c5a468973d7d4a7f2cf32a4e7fb;hpb=7a03009e08d9d15b796d425bb079607aca8751f4;p=core.git diff --git a/inc/classes/main/crypto/class_CryptoHelper.php b/inc/classes/main/crypto/class_CryptoHelper.php index b8bbbbe2..03458ee5 100644 --- a/inc/classes/main/crypto/class_CryptoHelper.php +++ b/inc/classes/main/crypto/class_CryptoHelper.php @@ -2,11 +2,11 @@ /** * A helper class for cryptographical things like hashing passwords and so on * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.shipsimu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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'); @@ -132,6 +132,26 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { $this->salt = substr(sha1($randomString), -$length, $length); } + /** + * 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 @@ -143,7 +163,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { * @param $withFixed Whether to include a fixed salt (not recommended in p2p applications) * @return $hashed The hashed and salted string */ - public function hashString ($str, $oldHash = '', $withFixed = true) { + public function hashString ($str, $oldHash = '', $withFixed = TRUE) { // Cast the string $str = (string) $str; @@ -161,7 +181,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { // Hash the password with salt //* DEBUG: */ echo "salt=".$salt."/plain=".$str."
\n"; - if ($withFixed === true) { + if ($withFixed === TRUE) { // Use additional fixed salt $hashed = $salt . md5(sprintf($this->getConfigInstance()->getConfigEntry('hash_extra_mask'), $salt,