19 declare(strict_types=1);
28 private const string COST =
'cost';
38 foreach ($config as $key => $value) {
39 if (strtolower($key) === self::COST) {
44 if (!isset($config[self::COST]) && static::class === self::class) {
60 $start = microtime(
true);
61 $encoder =
new self([self::COST => (string) $cost]);
62 $encoder->encodePassword(
'test',
'');
63 $end = microtime(
true);
64 }
while (($end - $start) < $time_target && $cost < 32);
82 $numeric_costs = (
int) $costs;
83 if ($numeric_costs < 4 || $numeric_costs > 31) {
86 $this->costs = sprintf(
'%1$02d', $numeric_costs);
96 return password_hash($raw, PASSWORD_BCRYPT, [
97 self::COST => $this->costs
103 return password_verify($raw, $encoded);
108 return password_needs_rehash($encoded, PASSWORD_BCRYPT, [
109 self::COST => $this->costs
__construct(array $config=[])
getName()
Returns a unique name/id of the concrete password encoder.
encodePassword(string $raw, string $salt)
Encodes the raw password.
isPasswordTooLong(string $password)
benchmarkCost(float $time_target=0.05)
requiresReencoding(string $encoded)
Returns whether the encoded password needs to be re-encoded.
isPasswordValid(string $encoded, string $raw, string $salt)
Checks a raw password against an encoded password.