aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorrxu <rxu@mail.ru>2019-12-28 00:15:08 +0700
committerrxu <rxu@mail.ru>2019-12-28 00:15:08 +0700
commit5dfba1b06473ecb0298d9b61fd9dec28ac60f884 (patch)
treea7b3a02ecb812d0cfeefef044fdc970685943b3c /phpBB
parent186a3d40c60b4d5f11e6f399737557ef08913078 (diff)
downloadforums-5dfba1b06473ecb0298d9b61fd9dec28ac60f884.tar
forums-5dfba1b06473ecb0298d9b61fd9dec28ac60f884.tar.gz
forums-5dfba1b06473ecb0298d9b61fd9dec28ac60f884.tar.bz2
forums-5dfba1b06473ecb0298d9b61fd9dec28ac60f884.tar.xz
forums-5dfba1b06473ecb0298d9b61fd9dec28ac60f884.zip
[ticket/16266] Optimize code
PHPBB3-16266
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/phpbb/passwords/driver/argon2i.php21
-rw-r--r--phpBB/phpbb/passwords/driver/base_native.php9
2 files changed, 14 insertions, 16 deletions
diff --git a/phpBB/phpbb/passwords/driver/argon2i.php b/phpBB/phpbb/passwords/driver/argon2i.php
index 3babbaa780..9aa2b6f14c 100644
--- a/phpBB/phpbb/passwords/driver/argon2i.php
+++ b/phpBB/phpbb/passwords/driver/argon2i.php
@@ -37,21 +37,12 @@ class argon2i extends base_native
{
parent::__construct($config, $helper);
- if ($this->is_sodium())
- {
- // For Sodium implementation, set special cost factor values (since PHP 7.4)
- // See https://wiki.php.net/rfc/sodium.argon.hash and PHPBB3-16266
- $this->memory_cost = max($memory_cost, 256*1024);
- $this->threads = 1;
- $this->time_cost = max($time_cost, 3);
- }
- else
- {
- // Otherwise don't allow cost factors to be below default settings
- $this->memory_cost = max($memory_cost, 1024);
- $this->threads = max($threads, 2);
- $this->time_cost = max($time_cost, 2);
- }
+ // For Sodium implementation, set special cost factor values (since PHP 7.4)
+ // See https://wiki.php.net/rfc/sodium.argon.hash and PHPBB3-16266
+ // Otherwise don't allow cost factors to be below default settings
+ $this->memory_cost = ($this->is_sodium()) ? max($memory_cost, 256*1024) : max($memory_cost, 1024);
+ $this->threads = ($this->is_sodium()) ? 1 : max($threads, 2);
+ $this->time_cost = ($this->is_sodium()) ? max($time_cost, 3) : max($time_cost, 2);
}
/**
diff --git a/phpBB/phpbb/passwords/driver/base_native.php b/phpBB/phpbb/passwords/driver/base_native.php
index 31d3465165..fa4f0995a5 100644
--- a/phpBB/phpbb/passwords/driver/base_native.php
+++ b/phpBB/phpbb/passwords/driver/base_native.php
@@ -66,7 +66,14 @@ abstract class base_native extends base
*/
public function is_sodium()
{
- return defined('PASSWORD_ARGON2_PROVIDER') && PASSWORD_ARGON2_PROVIDER == 'sodium';
+ static $is_sodium;
+
+ if (empty($is_sodium))
+ {
+ $is_sodium = defined('PASSWORD_ARGON2_PROVIDER') && PASSWORD_ARGON2_PROVIDER == 'sodium';
+ }
+
+ return $is_sodium;
}
/**