From b00f61193efc3cc8340585ca70fef84a571866d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=81ojewski?= Date: Wed, 13 Jun 2018 19:31:56 +0200 Subject: [PATCH] Fix "Use of undefined constant" error for PHP below 7.2. --- lib/Crypto/CryptArgon2.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/Crypto/CryptArgon2.php b/lib/Crypto/CryptArgon2.php index a8c2d3e..14efb64 100644 --- a/lib/Crypto/CryptArgon2.php +++ b/lib/Crypto/CryptArgon2.php @@ -54,15 +54,22 @@ class CryptArgon2 extends AbstractAlgorithm * @param int $threads Number of threads to use for computing. */ public function __construct( - IL10N $localization, - $memoryCost = PASSWORD_ARGON2_DEFAULT_MEMORY_COST, - $timeCost = PASSWORD_ARGON2_DEFAULT_TIME_COST, - $threads = PASSWORD_ARGON2_DEFAULT_THREADS + IL10N $localization, $memoryCost = -1, $timeCost = -1, $threads = -1 ) { if (version_compare(PHP_VERSION, "7.2.0") === -1) { throw new \RuntimeException( "PASSWORD_ARGON2I requires PHP 7.2.0 or above." ); + } else { + if ($memoryCost === -1) { + $memoryCost = PASSWORD_ARGON2_DEFAULT_MEMORY_COST; + } + if ($timeCost === -1) { + $timeCost = PASSWORD_ARGON2_DEFAULT_TIME_COST; + } + if ($threads === -1) { + $threads = PASSWORD_ARGON2_DEFAULT_THREADS; + } } parent::__construct($localization);