From: Roland Haeder Date: Tue, 26 May 2015 22:19:22 +0000 (+0200) Subject: Added check for "scrypt feature" (if no config entry is set, it assumed not being... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c383f8560b321f2295623831bae369810df1c0e1;p=core.git Added check for "scrypt feature" (if no config entry is set, it assumed not being there). Signed-off-by: Roland Häder --- diff --git a/inc/classes/main/scrypt/class_Scrypt.php b/inc/classes/main/scrypt/class_Scrypt.php index 3bc5d76c..8a9ec47e 100644 --- a/inc/classes/main/scrypt/class_Scrypt.php +++ b/inc/classes/main/scrypt/class_Scrypt.php @@ -51,7 +51,7 @@ abstract class Scrypt extends BaseFrameworkSystem * * @return int */ - protected static function strlen( $str ) { + protected static function strlen ($str) { static $isShadowed = null; if ($isShadowed === null) { @@ -73,7 +73,7 @@ abstract class Scrypt extends BaseFrameworkSystem * * @return string The salt */ - public static function generateScryptSalt($length = 8) + public static function generateScryptSalt ($length = 8) { $buffer = ''; $buffer_valid = false; @@ -128,8 +128,13 @@ abstract class Scrypt extends BaseFrameworkSystem * * @return string The hashed password */ - public static function hashScrypt($password, $salt = false, $N = 16384, $r = 8, $p = 1) + public static function hashScrypt ($password, $salt = false, $N = 16384, $r = 8, $p = 1) { + if ((!FrameworkConfiguration::getSelfInstance()->isConfigEntrySet('extension_scrypt_loaded')) || (FrameworkConfiguration::getSelfInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE)) { + // Feature has been disabled + throw new \InvalidArgumentException('Feature "scrypt" disabled.'); + } + if ($N == 0 || ($N & ($N - 1)) != 0) { throw new \InvalidArgumentException('N must be > 0 and a power of 2'); } @@ -162,13 +167,18 @@ abstract class Scrypt extends BaseFrameworkSystem * * @return boolean If the clear text matches */ - public static function checkScrypt($password, $hash) + public static function checkScrypt ($password, $hash) { // Is there actually a hash? if (!$hash) { return false; } + if ((!FrameworkConfiguration::getSelfInstance()->isConfigEntrySet('extension_scrypt_loaded')) || (FrameworkConfiguration::getSelfInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE)) { + // Feature has been disabled + throw new \InvalidArgumentException('Feature "scrypt" disabled.'); + } + list ($N, $r, $p, $salt, $hash) = explode('$', $hash); // No empty fields? @@ -206,7 +216,7 @@ abstract class Scrypt extends BaseFrameworkSystem * * @return boolean If the two strings match. */ - public static function compareScryptHashes($expected, $actual) + public static function compareScryptHashes ($expected, $actual) { $expected = (string) $expected; $actual = (string) $actual;