W3cubDocs

/Symfony 4.1

BCryptPasswordEncoder

class BCryptPasswordEncoder extends BasePasswordEncoder implements SelfSaltingEncoderInterface

Constants

MAX_PASSWORD_LENGTH

Methods

array demergePasswordAndSalt(string $mergedPasswordSalt)

Demerges a merge password and salt string.

from BasePasswordEncoder
string mergePasswordAndSalt(string $password, string $salt)

Merges a password and a salt.

from BasePasswordEncoder
bool comparePasswords(string $password1, string $password2)

Compares two passwords.

from BasePasswordEncoder
bool isPasswordTooLong(string $password)

Checks if the password is too long.

from BasePasswordEncoder
__construct(int $cost)
string encodePassword(string $raw, string $salt)

Encodes the raw password.

bool isPasswordValid(string $encoded, string $raw, string $salt)

Checks a raw password against an encoded password.

Details

protected array demergePasswordAndSalt(string $mergedPasswordSalt)

Demerges a merge password and salt string.

Parameters

string $mergedPasswordSalt The merged password and salt string

Return Value

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

protected string mergePasswordAndSalt(string $password, string $salt)

Merges a password and a salt.

Parameters

string $password The password to be used
string $salt The salt to be used

Return Value

string a merged password and salt

Exceptions

InvalidArgumentException

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

Compares two passwords.

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

Parameters

string $password1 The first password
string $password2 The second password

Return Value

bool true if the two passwords are the same, false otherwise

protected bool isPasswordTooLong(string $password)

Checks if the password is too long.

Parameters

string $password The password to check

Return Value

bool true if the password is too long, false otherwise

__construct(int $cost)

Parameters

int $cost The algorithmic cost that should be used

Exceptions

RuntimeException When no BCrypt encoder is available
InvalidArgumentException if cost is out of range

string encodePassword(string $raw, string $salt)

Encodes the raw password.

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

string $raw The password to encode
string $salt The salt

Return Value

string The encoded password

Exceptions

BadCredentialsException when the given password is too long

See also

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.
http://lxr.php.net/xref/PHP_5_5/ext/standard/password.c#111

bool isPasswordValid(string $encoded, string $raw, string $salt)

Checks a raw password against an encoded password.

Parameters

string $encoded An encoded password
string $raw A raw password
string $salt The salt

Return Value

bool true if the password is valid, false otherwise

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.html