2

I need to encrypt a string in Symfony using bcrypt. The string is not a password it's an API Key that will be saved in database as bcrypt hash. To do that I am doing simply

$key = 'superSecretKey';
$options = array('cost' => 12);
$hash = password_hash($key, PASSWORD_BCRYPT, $options)

The problem is that password_hash() works only on PHP 5 >= 5.5.0 and I still want to preserve compatibility with PHP 5.4

Is there a "Symfony way" of encrypting string so in case of PHP version below 5.5 it will use ircmaxell/password_compat like Symfony security is doing?

1 Answer 1

4

ircmaxell/password_compat is a polyfill library. You can just add it to your dependencies and call the password_hash() function without worrying about the PHP version. For PHP 5.5+ it will use the native PHP version, for lower versions it will resort to the library.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.