From 3bf725d7e03e8995a9f54396a5ab817468718d30 Mon Sep 17 00:00:00 2001 From: kondou <kondou@ts.unde.re> Date: Thu, 4 Sep 2014 15:13:30 +0200 Subject: [PATCH] Adapt token size to new generation and add an option for free length specification Minimum size is 3 = 46656 tokens, maximum size is 64, which is what our DB allows. --- lib/private/share/share.php | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/private/share/share.php b/lib/private/share/share.php index dfe0f65340..5bebd16a9b 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -640,22 +640,11 @@ class Share extends \OC\Share\Constants { if (isset($oldToken)) { $token = $oldToken; } else { - // Determine how long the token should be - switch (\OC_Config::getValue("sharing_token_length", 3)) { - case 1: - $tokenLength = 4; - break; - case 2: - $tokenLength = 8; - break; - // Default is 3, so skip the 3 block - case 4: - $tokenLength = 32; - break; - // Anything other than 1-4 should be default 3 - default: - $tokenLength = 16; - break; + $tokenLength = \OC_Config::getValue("sharing_token_length", 13); + + // Enforce a limit on token length + if ($tokenLength < 3 || $tokenLength > 64) { + $tokenLength = 13; } $token = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate($tokenLength, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS -- GitLab