19 declare(strict_types=1);
36 if (!empty($config)) {
37 foreach ($config as $key => $value) {
38 switch (strtolower($key)) {
39 case self::CONFIG_KEY_MEMORY_COST:
43 case self::CONFIG_KEY_TIME_COST:
47 case self::CONFIG_KEY_THREADS:
55 if (!isset($config[self::CONFIG_KEY_MEMORY_COST])) {
58 if (!isset($config[self::CONFIG_KEY_TIME_COST])) {
59 $this->
setTimeCost(PASSWORD_ARGON2_DEFAULT_TIME_COST);
61 if (!isset($config[self::CONFIG_KEY_THREADS])) {
62 $this->
setThreads(PASSWORD_ARGON2_DEFAULT_THREADS);
74 $this->memory_cost = $memory_costs;
105 parent::isSupportedByRuntime() &&
106 version_compare(phpversion(),
'7.3.0',
'>=') &&
107 defined(
'PASSWORD_ARGON2ID')
117 return password_hash($raw, PASSWORD_ARGON2ID, [
119 self::CONFIG_KEY_TIME_COST => $this->
getTimeCost(),
120 self::CONFIG_KEY_THREADS => $this->
getThreads(),
126 return password_verify($raw, $encoded);
131 return password_needs_rehash($encoded, PASSWORD_ARGON2ID, [
133 self::CONFIG_KEY_TIME_COST => $this->
getTimeCost(),
134 self::CONFIG_KEY_THREADS => $this->
getThreads(),
getName()
Returns a unique name/id of the concrete password encoder.
setTimeCost(int $time_cost)
isPasswordValid(string $encoded, string $raw, string $salt)
Checks a raw password against an encoded password.
__construct(array $config=[])
isPasswordTooLong(string $password)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isSupportedByRuntime()
Returns whether the encoder is supported by the runtime (PHP, HHVM, ...)
const CONFIG_KEY_MEMORY_COST
requiresReencoding(string $encoded)
Returns whether the encoded password needs to be re-encoded.
setMemoryCost(int $memory_costs)
const CONFIG_KEY_TIME_COST
encodePassword(string $raw, string $salt)
Encodes the raw password.