amerza
amerza

Reputation: 69

bcrypt on php 5.2 or 5.3

I want to use bcrypt hashing in PHP and shared servers I would use are ordinary Unix and I cannot install anything on them. The version of my php would be 5.3 or 5.2 and not 5.5 and this code using password_hash will not work.

$password = '123456';
$options = array(
    'cost' => 7,
    'salt' => 'BCryptRequires22Chrcts',
);
$hash=password_hash($password, PASSWORD_BCRYPT, $options);

even though there are a lot of conversations about bcrypt, I didn't find any clear command or code example about it. php.net has a page about crypt command which is so confuting for a beginner. all I want is to implement such a function:

bcrypt($password,$salt)

is there any simple command(not dozens of codes including loops) to do that? if not, is there any vulnerability purified code to download?

thanks in advance

Upvotes: 2

Views: 5174

Answers (2)

Spudley
Spudley

Reputation: 168685

There is a library available to allow PHP 5.3 and 5.4 to use the new 5.5 password_xxx() functions.

You can download it from here on Github.

This library is written by the same PHP core developer who wrote the actual built-in password_xxx() functions in PHP 5.5, so it is 100% compatible. Just include it in your code and PHP 5.3 and 5.4 will be able to use these functions just as PHP 5.5 can.

The library is not compatible with PHP 5.2, because 5.2 is no longer supported (and has not been supported for over two years now). If you're using 5.2 you should be urgently considering upgrading.

Please also note that even on PHP 5.3, you need to be using a version greater than 5.3.7, as it relies on a feature that was fixed in that patch release. (the library will test for this when you run it).

If you absolutely can't upgrade your PHP to a version that is compatible with this library, then the next best option is to use an older password manager library written by the same author, called PasswordLib.

Upvotes: 3

JimL
JimL

Reputation: 2541

Not sure for 5.2, but for 5.3.7+ theres a simple file you can include to add this PHP5.5 functionality.

There is a compatibility pack available for PHP versions 5.3.7 and later, so you don't have to wait on version 5.5 for using this function. It comes in form of a single php file: https://github.com/ircmaxell/password_compat

Upvotes: 0

Related Questions