1 <?php declare(strict_types=1);
4 require_once
'Services/Password/classes/encoders/class.ilBcryptPhpPasswordEncoder.php';
38 foreach (
$config as $key => $value) {
39 switch (strtolower($key)) {
40 case 'ignore_security_flaw':
44 case 'data_directory':
57 protected function init() : void
67 return PHP_VERSION_ID >= 50307;
100 $this->backward_compatibility = (bool) $backward_compatibility;
116 $this->is_security_flaw_ignored = (bool) $is_security_flaw_ignored;
149 return $this->
encode($raw, $salt);
196 protected function encode(
string $raw,
string $userSecret) : string
199 $hashedPassword = hash_hmac(
201 str_pad($raw, strlen($raw) * 4, sha1($userSecret), STR_PAD_BOTH),
206 str_shuffle(str_repeat(
'./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 22)),
222 'The bcrypt implementation used by PHP can contain a security flaw ' .
223 'using passwords with 8-bit characters. ' .
224 'We suggest to upgrade to PHP 5.3.7+ or use passwords with only 7-bit characters.' 229 $saltedPassword = crypt($hashedPassword, $prefix . $this->
getCosts() .
'$' . $salt);
230 if (strlen($saltedPassword) <= 13) {
234 return $saltedPassword;
244 protected function check(
string $encoded,
string $raw,
string $salt) : bool
246 $hashedPassword = hash_hmac(
248 str_pad($raw, strlen($raw) * 4, sha1($salt), STR_PAD_BOTH),
253 return $this->
comparePasswords($encoded, crypt($hashedPassword, substr($encoded, 0, 30)));
271 if (strlen(trim($contents))) {
298 "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=[])