ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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...
 
 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...
 
 getName ()
 Returns a unique name/id of the concrete password encoder. More...
 
 requiresSalt ()
 Returns whether the encoder requires a salt. More...
 
 requiresReencoding (string $encoded)
 Returns whether the encoded password needs to be re-encoded. More...
 
 isSupportedByRuntime ()
 Returns whether the encoder is supported by the runtime (PHP, HHVM, ...) More...
 

Private Attributes

const string CONFIG_KEY_TIME_COST = 'time_cost'
 
const string CONFIG_KEY_MEMORY_COST = 'memory_cost'
 
const string 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.

35 {
36 if (!empty($config)) {
37 foreach ($config as $key => $value) {
38 switch (strtolower($key)) {
40 $this->setMemoryCost($value);
41 break;
42
44 $this->setTimeCost($value);
45 break;
46
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, ...)

References CONFIG_KEY_MEMORY_COST, CONFIG_KEY_THREADS, CONFIG_KEY_TIME_COST, isSupportedByRuntime(), setMemoryCost(), setThreads(), and setTimeCost().

+ 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.

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 }
Class for user password exception handling in ILIAS.

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

Referenced by ilArgon2IdPasswordEncoderTest\testReencodingIsDetectedWhenNecessary().

+ 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().

+ 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.

97 : string
98 {
99 return 'argon2id';
100 }

Referenced by ilArgon2IdPasswordEncoderTest\testNameShouldBeArgon2id().

+ 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().

+ 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().

+ 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.

124 : bool
125 {
126 return password_verify($raw, $encoded);
127 }

◆ isSupportedByRuntime()

ilArgon2idPasswordEncoder::isSupportedByRuntime ( )

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

Reimplemented from ilBasePasswordEncoder.

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

102 : bool
103 {
104 return (
105 parent::isSupportedByRuntime() &&
106 version_compare(phpversion(), '7.3.0', '>=') &&
107 defined('PASSWORD_ARGON2ID')
108 );
109 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ requiresReencoding()

ilArgon2idPasswordEncoder::requiresReencoding ( string  $encoded)

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

Reimplemented from ilBasePasswordEncoder.

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

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 }

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

Referenced by ilArgon2IdPasswordEncoderTest\testReencodingIsDetectedWhenNecessary().

+ 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.

72 : void
73 {
74 $this->memory_cost = $memory_costs;
75 }

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

+ Here is the caller graph for this function:

◆ setThreads()

ilArgon2idPasswordEncoder::setThreads ( int  $threads)

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

92 : void
93 {
94 $this->threads = $threads;
95 }

References $threads.

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

+ Here is the caller graph for this function:

◆ setTimeCost()

ilArgon2idPasswordEncoder::setTimeCost ( int  $time_cost)

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

82 : void
83 {
84 $this->time_cost = $time_cost;
85 }

References $time_cost.

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

+ 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 string ilArgon2idPasswordEncoder::CONFIG_KEY_MEMORY_COST = 'memory_cost'
private

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

Referenced by __construct().

◆ CONFIG_KEY_THREADS

const string ilArgon2idPasswordEncoder::CONFIG_KEY_THREADS = 'threads'
private

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

Referenced by __construct().

◆ CONFIG_KEY_TIME_COST

const string ilArgon2idPasswordEncoder::CONFIG_KEY_TIME_COST = 'time_cost'
private

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

Referenced by __construct().


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