File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 14331433 */
14341434'tempdirectory ' => '/tmp/nextcloudtemp ' ,
14351435
1436+ /**
1437+ * Hashing
1438+ *
1439+ * Nextcloud uses the Argon2 algorithm (with PHP >= 7.2) to create hashes by its
1440+ * own and exposes its configuration options as following. More information can
1441+ * be found at: https://www.php.net/manual/en/function.password-hash.php
1442+ */
1443+
1444+ /**
1445+ * The allowed maximum memory in KiB to be used by the algorithm for computing a
1446+ * hash. The smallest possible value is 8. Values that undershoot the minimum
1447+ * will be ignored in favor of the default.
1448+ */
1449+ 'hashingMemoryCost ' => PASSWORD_ARGON2_DEFAULT_MEMORY_COST ,
1450+
1451+ /**
1452+ * The allowed maximum time in seconds that can be used by the algorithm for
1453+ * computing a hash. The value must be an integer, and the minimum value is 1.
1454+ * Values that undershoot the minimum will be ignored in favor of the default.
1455+ */
1456+ 'hashingTimeCost ' => PASSWORD_ARGON2_DEFAULT_TIME_COST ,
1457+
1458+ /**
1459+ * The allowed number of CPU threads that can be used by the algorithm for
1460+ * computing a hash. The value must be an integer, and the minimum value is 1.
1461+ * Rationally it does not help to provide a number higher than the available
1462+ * threads on the machine. Values that undershoot the minimum will be ignored
1463+ * in favor of the default.
1464+ */
1465+ 'hashingThreads ' => PASSWORD_ARGON2_DEFAULT_THREADS ,
1466+
14361467/**
14371468 * The hashing cost used by hashes generated by Nextcloud
14381469 * Using a higher value requires more time and CPU power to calculate the hashes
Original file line number Diff line number Diff line change @@ -63,6 +63,20 @@ class Hasher implements IHasher {
6363 public function __construct (IConfig $ config ) {
6464 $ this ->config = $ config ;
6565
66+ if (\defined ('PASSWORD_ARGON2I ' )) {
67+ // password_hash fails, when the minimum values are undershot.
68+ // In this case, ignore and revert to default
69+ if ($ this ->config ->getSystemValueInt ('hashingMemoryCost ' , PASSWORD_ARGON2_DEFAULT_MEMORY_COST ) >= 8 ) {
70+ $ this ->options ['memory_cost ' ] = $ this ->config ->getSystemValueInt ('hashingMemoryCost ' , PASSWORD_ARGON2_DEFAULT_MEMORY_COST );
71+ }
72+ if ($ this ->config ->getSystemValueInt ('hashingTimeCost ' , PASSWORD_ARGON2_DEFAULT_MEMORY_COST ) >= 1 ) {
73+ $ this ->options ['time_cost ' ] = $ this ->config ->getSystemValueInt ('hashingTimeCost ' , PASSWORD_ARGON2_DEFAULT_TIME_COST );
74+ }
75+ if ($ this ->config ->getSystemValueInt ('hashingThreads ' , PASSWORD_ARGON2_DEFAULT_MEMORY_COST ) >= 1 ) {
76+ $ this ->options ['threads ' ] = $ this ->config ->getSystemValueInt ('hashingThreads ' , PASSWORD_ARGON2_DEFAULT_THREADS );
77+ }
78+ }
79+
6680 $ hashingCost = $ this ->config ->getSystemValue ('hashingCost ' , null );
6781 if (!\is_null ($ hashingCost )) {
6882 $ this ->options ['cost ' ] = $ hashingCost ;
You can’t perform that action at this time.
0 commit comments