mediatekformation

BCryptPasswordEncoder extends BasePasswordEncoder
in package
implements SelfSaltingEncoderInterface

BasePasswordEncoder is the base class for all password encoders.

Tags
author

Elnur Abdurrakhimov elnur@elnur.pro

author

Terje Bråten terje@braten.be

deprecated

since Symfony 4.3, use NativePasswordEncoder instead

Interfaces, Classes, Traits and Enums

SelfSaltingEncoderInterface
SelfSaltingEncoderInterface is a marker interface for encoders that do not require a user-generated salt.

Table of Contents

MAX_PASSWORD_LENGTH  = 72
$cost  : mixed
__construct()  : mixed
encodePassword()  : string
Encodes the raw password.
isPasswordValid()  : mixed
{@inheritdoc}
needsRehash()  : bool
{@inheritdoc}
comparePasswords()  : bool
Compares two passwords.
demergePasswordAndSalt()  : array<string|int, mixed>
Demerges a merge password and salt string.
isPasswordTooLong()  : bool
Checks if the password is too long.
mergePasswordAndSalt()  : string
Merges a password and a salt.

Constants

Properties

Methods

__construct()

public __construct(int $cost) : mixed
Parameters
$cost : int

The algorithmic cost that should be used

Tags
throws
RuntimeException

When no BCrypt encoder is available

throws
InvalidArgumentException

if cost is out of range

Return values
mixed

encodePassword()

Encodes the raw password.

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

It doesn't work with PHP versions lower than 5.3.7, since the password compat library uses CRYPT_BLOWFISH hash type with the "$2y$" salt prefix (which is not available in the early PHP versions).

Parameters
$raw : string

The password to encode

$salt : string

The salt

Tags
see
https://github.com/ircmaxell/password_compat/issues/10#issuecomment-11203833

It is almost best to not pass a salt and let PHP generate one for you.

see
http://lxr.php.net/xref/PHP_5_5/ext/standard/password.c#111
throws
BadCredentialsException

when the given password is too long

Return values
string

The encoded password

isPasswordValid()

{@inheritdoc}

public isPasswordValid(mixed $encoded, mixed $raw, mixed $salt) : mixed
Parameters
$encoded : mixed
$raw : mixed
$salt : mixed
Return values
mixed

needsRehash()

{@inheritdoc}

public needsRehash(string $encoded) : bool
Parameters
$encoded : string
Return values
bool

comparePasswords()

Compares two passwords.

protected comparePasswords(string $password1, string $password2) : bool

This method implements a constant-time algorithm to compare passwords to avoid (remote) timing attacks.

Parameters
$password1 : string

The first password

$password2 : string

The second password

Return values
bool

true if the two passwords are the same, false otherwise

demergePasswordAndSalt()

Demerges a merge password and salt string.

protected demergePasswordAndSalt(string $mergedPasswordSalt) : array<string|int, mixed>
Parameters
$mergedPasswordSalt : string

The merged password and salt string

Return values
array<string|int, mixed>

An array where the first element is the password and the second the salt

isPasswordTooLong()

Checks if the password is too long.

protected isPasswordTooLong(string $password) : bool
Parameters
$password : string

The password to check

Return values
bool

true if the password is too long, false otherwise

mergePasswordAndSalt()

Merges a password and a salt.

protected mergePasswordAndSalt(string $password, string|null $salt) : string
Parameters
$password : string

The password to be used

$salt : string|null

The salt to be used

Tags
throws
InvalidArgumentException
Return values
string

a merged password and salt

Search results