]> source.dussan.org Git - nextcloud-server.git/commitdiff
ignore values that undershoot the minimum, go with default
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Tue, 21 Jan 2020 10:58:13 +0000 (11:58 +0100)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Fri, 21 Feb 2020 13:51:44 +0000 (14:51 +0100)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
lib/private/Security/Hasher.php

index 696fd671361be39af6e395ca08cf04f1ae301001..a65ecabb6204bd15cc55dd6af67693506ecd8ed8 100644 (file)
@@ -61,11 +61,19 @@ class Hasher implements IHasher {
        public function __construct(IConfig $config) {
                $this->config = $config;
 
-               $this->options = [
-                       'memory_cost' => $this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST),
-                       'time_cost' => $this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST),
-                       'threads' => $this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS),
-               ];
+               if (\defined('PASSWORD_ARGON2I')) {
+                       // password_hash fails, when the minimum values are undershot.
+                       // In this case, ignore and revert to default
+                       if ($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 8) {
+                               $this->options['memory_cost'] = $this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST);
+                       }
+                       if ($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 1) {
+                               $this->options['time_cost'] = $this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST);
+                       }
+                       if ($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 1) {
+                               $this->options['threads'] = $this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS);
+                       }
+               }
 
                $hashingCost = $this->config->getSystemValue('hashingCost', null);
                if(!\is_null($hashingCost)) {