1 <?php declare(strict_types=1);
4 require_once
'Services/Password/classes/encoders/class.ilBcryptPhpPasswordEncoder.php';
39 foreach (
$config as $key => $value) {
40 switch (strtolower($key)) {
41 case 'ignore_security_flaw':
45 case 'data_directory':
58 protected function init() : void
68 return PHP_VERSION_ID >= 50307;
101 $this->backward_compatibility = (bool) $backward_compatibility;
117 $this->is_security_flaw_ignored = (bool) $is_security_flaw_ignored;
150 return $this->
encode($raw, $salt);
197 protected function encode(
string $raw,
string $userSecret) : string
200 $hashedPassword = hash_hmac(
202 str_pad($raw, strlen($raw) * 4, sha1($userSecret), STR_PAD_BOTH),
207 str_shuffle(str_repeat(
'./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 22)),
223 'The bcrypt implementation used by PHP can contain a security flaw ' .
224 'using passwords with 8-bit characters. ' .
225 'We suggest to upgrade to PHP 5.3.7+ or use passwords with only 7-bit characters.' 230 $saltedPassword = crypt($hashedPassword, $prefix . $this->
getCosts() .
'$' . $salt);
231 if (strlen($saltedPassword) <= 13) {
235 return $saltedPassword;
245 protected function check(
string $encoded,
string $raw,
string $salt) : bool
247 $hashedPassword = hash_hmac(
249 str_pad($raw, strlen($raw) * 4, sha1($salt), STR_PAD_BOTH),
254 return $this->
comparePasswords($encoded, crypt($hashedPassword, substr($encoded, 0, 30)));
272 if (strlen(trim($contents))) {
299 "Could not store the client salt in: %s. Please contact an administrator.",
const SALT_STORAGE_FILENAME
check(string $encoded, string $raw, string $salt)
Verifies a bcrypt encoded string.
setBackwardCompatibility(bool $backward_compatibility)
Set the backward compatibility $2a$ instead of $2y$ for PHP 5.3.7+.
$is_security_flaw_ignored
isBackwardCompatibilityEnabled()
comparePasswords(string $knownString, string $userString)
Compares two passwords.
setIsSecurityFlawIgnored(bool $is_security_flaw_ignored)
encodePassword(string $raw, string $salt)
encode(string $raw, string $userSecret)
Generates a bcrypt encoded string.
Class for user password exception handling in ILIAS.
isPasswordTooLong(string $password)
Checks if the password is too long.
static getBytes($length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.
setDataDirectory(string $data_directory)
setClientSalt(?string $client_salt)
requiresReencoding(string $encoded)
__construct(Container $dic, ilPlugin $plugin)
isPasswordValid(string $encoded, string $raw, string $salt)
__construct(array $config=[])