ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilArgon2idPasswordEncoder Class Reference
+ Inheritance diagram for ilArgon2idPasswordEncoder:
+ Collaboration diagram for ilArgon2idPasswordEncoder:

Public Member Functions

 __construct (array $config=[])
 
 getMemoryCost ()
 
 setMemoryCost (int $memory_costs)
 
 getTimeCost ()
 
 setTimeCost (int $time_cost)
 
 getThreads ()
 
 setThreads (int $threads)
 
 getName ()
 Returns a unique name/id of the concrete password encoder. More...
 
 isSupportedByRuntime ()
 Returns whether the encoder is supported by the runtime (PHP, HHVM, ...) More...
 
 encodePassword (string $raw, string $salt)
 Encodes the raw password. More...
 
 isPasswordValid (string $encoded, string $raw, string $salt)
 Checks a raw password against an encoded password. More...
 
 requiresReencoding (string $encoded)
 Returns whether the encoded password needs to be re-encoded. More...
 
- Public Member Functions inherited from ilBasePasswordEncoder
 isSupportedByRuntime ()
 Returns whether the encoder is supported by the runtime (PHP, HHVM, ...) More...
 
 requiresSalt ()
 Returns whether the encoder requires a salt. More...
 
 requiresReencoding (string $encoded)
 Returns whether the encoded password needs to be re-encoded. More...
 

Private Attributes

const CONFIG_KEY_TIME_COST = 'time_cost'
 
const CONFIG_KEY_MEMORY_COST = 'memory_cost'
 
const CONFIG_KEY_THREADS = 'threads'
 
int $memory_cost = null
 
int $time_cost = null
 
int $threads = null
 

Additional Inherited Members

- Protected Member Functions inherited from ilBasePasswordEncoder
 comparePasswords (string $knownString, string $userString)
 Compares two passwords. More...
 
 isPasswordTooLong (string $password)
 

Detailed Description

Definition at line 21 of file class.ilArgon2IdPasswordEncoder.php.

Constructor & Destructor Documentation

◆ __construct()

ilArgon2idPasswordEncoder::__construct ( array  $config = [])
Parameters
array<string,mixed>$config

Definition at line 34 of file class.ilArgon2IdPasswordEncoder.php.

References isSupportedByRuntime(), setMemoryCost(), setThreads(), and setTimeCost().

35  {
36  if (!empty($config)) {
37  foreach ($config as $key => $value) {
38  switch (strtolower($key)) {
39  case self::CONFIG_KEY_MEMORY_COST:
40  $this->setMemoryCost($value);
41  break;
42 
43  case self::CONFIG_KEY_TIME_COST:
44  $this->setTimeCost($value);
45  break;
46 
47  case self::CONFIG_KEY_THREADS:
48  $this->setThreads($value);
49  break;
50  }
51  }
52  }
53 
54  if ($this->isSupportedByRuntime() && static::class == self::class) {
55  if (!isset($config[self::CONFIG_KEY_MEMORY_COST])) {
56  $this->setMemoryCost(PASSWORD_ARGON2_DEFAULT_MEMORY_COST);
57  }
58  if (!isset($config[self::CONFIG_KEY_TIME_COST])) {
59  $this->setTimeCost(PASSWORD_ARGON2_DEFAULT_TIME_COST);
60  }
61  if (!isset($config[self::CONFIG_KEY_THREADS])) {
62  $this->setThreads(PASSWORD_ARGON2_DEFAULT_THREADS);
63  }
64  }
65  }
isSupportedByRuntime()
Returns whether the encoder is supported by the runtime (PHP, HHVM, ...)
+ Here is the call graph for this function:

Member Function Documentation

◆ encodePassword()

ilArgon2idPasswordEncoder::encodePassword ( string  $raw,
string  $salt 
)

Encodes the raw password.

Parameters
string$rawThe password to encode
string$saltThe salt
Returns
string The encoded password

Implements ilPasswordEncoder.

Definition at line 111 of file class.ilArgon2IdPasswordEncoder.php.

References getMemoryCost(), getThreads(), getTimeCost(), and ilBasePasswordEncoder\isPasswordTooLong().

Referenced by ilArgon2IdPasswordEncoderTest\testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding(), ilArgon2IdPasswordEncoderTest\testPasswordShouldBeCorrectlyEncodedAndVerified(), and ilArgon2IdPasswordEncoderTest\testReencodingIsDetectedWhenNecessary().

111  : string
112  {
113  if ($this->isPasswordTooLong($raw)) {
114  throw new ilPasswordException('Invalid password.');
115  }
116 
117  return password_hash($raw, PASSWORD_ARGON2ID, [
118  self::CONFIG_KEY_MEMORY_COST => $this->getMemoryCost(),
119  self::CONFIG_KEY_TIME_COST => $this->getTimeCost(),
120  self::CONFIG_KEY_THREADS => $this->getThreads(),
121  ]);
122  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMemoryCost()

ilArgon2idPasswordEncoder::getMemoryCost ( )

Definition at line 67 of file class.ilArgon2IdPasswordEncoder.php.

References $memory_cost.

Referenced by encodePassword(), and requiresReencoding().

67  : int
68  {
69  return $this->memory_cost;
70  }
+ Here is the caller graph for this function:

◆ getName()

ilArgon2idPasswordEncoder::getName ( )

Returns a unique name/id of the concrete password encoder.

Implements ilPasswordEncoder.

Definition at line 97 of file class.ilArgon2IdPasswordEncoder.php.

Referenced by ilArgon2IdPasswordEncoderTest\testNameShouldBeArgon2id().

97  : string
98  {
99  return 'argon2id';
100  }
+ Here is the caller graph for this function:

◆ getThreads()

ilArgon2idPasswordEncoder::getThreads ( )

Definition at line 87 of file class.ilArgon2IdPasswordEncoder.php.

References $threads.

Referenced by encodePassword(), and requiresReencoding().

87  : int
88  {
89  return $this->threads;
90  }
+ Here is the caller graph for this function:

◆ getTimeCost()

ilArgon2idPasswordEncoder::getTimeCost ( )

Definition at line 77 of file class.ilArgon2IdPasswordEncoder.php.

References $time_cost.

Referenced by encodePassword(), and requiresReencoding().

77  : int
78  {
79  return $this->time_cost;
80  }
+ Here is the caller graph for this function:

◆ isPasswordValid()

ilArgon2idPasswordEncoder::isPasswordValid ( string  $encoded,
string  $raw,
string  $salt 
)

Checks a raw password against an encoded password.

The raw password has to be injected into the encoder instance before.

Parameters
string$encodedAn encoded password
string$rawA raw password
string$saltThe salt, may be empty
Returns
Boolean true if the password is valid, false otherwise

Implements ilPasswordEncoder.

Definition at line 124 of file class.ilArgon2IdPasswordEncoder.php.

Referenced by ilArgon2IdPasswordEncoderTest\testPasswordShouldBeCorrectlyEncodedAndVerified(), and ilArgon2IdPasswordEncoderTest\testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength().

124  : bool
125  {
126  return password_verify($raw, $encoded);
127  }
+ Here is the caller graph for this function:

◆ isSupportedByRuntime()

ilArgon2idPasswordEncoder::isSupportedByRuntime ( )

Returns whether the encoder is supported by the runtime (PHP, HHVM, ...)

Implements ilPasswordEncoder.

Definition at line 102 of file class.ilArgon2IdPasswordEncoder.php.

Referenced by __construct().

102  : bool
103  {
104  return (
105  parent::isSupportedByRuntime() &&
106  version_compare(phpversion(), '7.3.0', '>=') &&
107  defined('PASSWORD_ARGON2ID')
108  );
109  }
+ Here is the caller graph for this function:

◆ requiresReencoding()

ilArgon2idPasswordEncoder::requiresReencoding ( string  $encoded)

Returns whether the encoded password needs to be re-encoded.

Implements ilPasswordEncoder.

Definition at line 129 of file class.ilArgon2IdPasswordEncoder.php.

References getMemoryCost(), getThreads(), and getTimeCost().

Referenced by ilArgon2IdPasswordEncoderTest\testReencodingIsDetectedWhenNecessary().

129  : bool
130  {
131  return password_needs_rehash($encoded, PASSWORD_ARGON2ID, [
132  self::CONFIG_KEY_MEMORY_COST => $this->getMemoryCost(),
133  self::CONFIG_KEY_TIME_COST => $this->getTimeCost(),
134  self::CONFIG_KEY_THREADS => $this->getThreads(),
135  ]);
136  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMemoryCost()

ilArgon2idPasswordEncoder::setMemoryCost ( int  $memory_costs)

Definition at line 72 of file class.ilArgon2IdPasswordEncoder.php.

Referenced by __construct(), and ilArgon2IdPasswordEncoderTest\testReencodingIsDetectedWhenNecessary().

72  : void
73  {
74  $this->memory_cost = $memory_costs;
75  }
+ Here is the caller graph for this function:

◆ setThreads()

ilArgon2idPasswordEncoder::setThreads ( int  $threads)

Definition at line 92 of file class.ilArgon2IdPasswordEncoder.php.

References $threads.

Referenced by __construct(), and ilArgon2IdPasswordEncoderTest\testReencodingIsDetectedWhenNecessary().

92  : void
93  {
94  $this->threads = $threads;
95  }
+ Here is the caller graph for this function:

◆ setTimeCost()

ilArgon2idPasswordEncoder::setTimeCost ( int  $time_cost)

Definition at line 82 of file class.ilArgon2IdPasswordEncoder.php.

References $time_cost.

Referenced by __construct(), and ilArgon2IdPasswordEncoderTest\testReencodingIsDetectedWhenNecessary().

82  : void
83  {
84  $this->time_cost = $time_cost;
85  }
+ Here is the caller graph for this function:

Field Documentation

◆ $memory_cost

int ilArgon2idPasswordEncoder::$memory_cost = null
private

Definition at line 27 of file class.ilArgon2IdPasswordEncoder.php.

Referenced by getMemoryCost().

◆ $threads

int ilArgon2idPasswordEncoder::$threads = null
private

Definition at line 29 of file class.ilArgon2IdPasswordEncoder.php.

Referenced by getThreads(), and setThreads().

◆ $time_cost

int ilArgon2idPasswordEncoder::$time_cost = null
private

Definition at line 28 of file class.ilArgon2IdPasswordEncoder.php.

Referenced by getTimeCost(), and setTimeCost().

◆ CONFIG_KEY_MEMORY_COST

const ilArgon2idPasswordEncoder::CONFIG_KEY_MEMORY_COST = 'memory_cost'
private

Definition at line 24 of file class.ilArgon2IdPasswordEncoder.php.

◆ CONFIG_KEY_THREADS

const ilArgon2idPasswordEncoder::CONFIG_KEY_THREADS = 'threads'
private

Definition at line 25 of file class.ilArgon2IdPasswordEncoder.php.

◆ CONFIG_KEY_TIME_COST

const ilArgon2idPasswordEncoder::CONFIG_KEY_TIME_COST = 'time_cost'
private

Definition at line 23 of file class.ilArgon2IdPasswordEncoder.php.


The documentation for this class was generated from the following file: