From 2ed1fa148954934a37ce31342c90cb2d90b80ecd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 13 Sep 2008 19:31:00 +0000 Subject: [PATCH] Fix for surfbar if code length is zero --- inc/databases.php | 2 +- inc/functions.php | 1 + inc/libs/surfbar_functions.php | 13 +++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/inc/databases.php b/inc/databases.php index fd7d2aa703..74de24b765 100644 --- a/inc/databases.php +++ b/inc/databases.php @@ -114,7 +114,7 @@ define('USAGE_BASE', "usage"); define('SERVER_URL', "http://www.mxchange.org"); // This current patch level -define('CURR_SVN_REVISION', "323"); +define('CURR_SVN_REVISION', "324"); // Take a prime number which is long (if you know a longer one please try it out!) define('_PRIME', 591623); diff --git a/inc/functions.php b/inc/functions.php index d9a2388fcb..59e8c8c4a9 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1182,6 +1182,7 @@ function GEN_RANDOM_CODE($length, $code, $uid, $DATA="") { // At least 10 numbers shall be secure enought! $len = $_CONFIG['code_length']; + if ($len == 0) $len = $length; if ($len == 0) $len = 10; // Cut off requested counts of number diff --git a/inc/libs/surfbar_functions.php b/inc/libs/surfbar_functions.php index 8b491c650a..3ca9d415d7 100644 --- a/inc/libs/surfbar_functions.php +++ b/inc/libs/surfbar_functions.php @@ -450,9 +450,18 @@ LIMIT %s", function SURFBAR_GENERATE_VALIDATION_CODE ($id, $salt="") { global $_CONFIG, $SURFBAR_CACHE; + // @TODO Invalid salt should be refused + $SURFBAR_CACHE['salt'] = "INVALID"; + + // Get code length from config + $length = $_CONFIG['code_length']; + + // Fix length to 10 + if ($length == 0) $length = 10; + // Generate a code until the length matches $valCode = ""; - while (strlen($valCode) != $_CONFIG['code_length']) { + while (strlen($valCode) != $length) { // Is the salt set? if (empty($salt)) { // Generate random hashed string @@ -465,7 +474,7 @@ function SURFBAR_GENERATE_VALIDATION_CODE ($id, $salt="") { } // ... and now the validation code - $valCode = GEN_RANDOM_CODE($_CONFIG['code_length'], sha1(SURFBAR_GET_SALT().":".$id), $GLOBALS['userid']); + $valCode = GEN_RANDOM_CODE($length, sha1(SURFBAR_GET_SALT().":".$id), $GLOBALS['userid']); //DEBUG_LOG(__FUNCTION__.":valCode={$valCode}"); } // END - while -- 2.39.2