Вопрос

OK. I've really do a big research, but I haven't got any crypting / hashing knowledge. On my own machine I've got php 5.5 and I'm using password_hash function. I just realized, that my online hosting has the maximum of PHP 5.4.

I've got a special class for encrypting, that's why there are (hopefully) not many changes to be done. Here is my simple code:

class Enigma {
    public static function hash($password) {
        return password_hash($password, PASSWORD_DEFAULT);
    }
    public static function verify($password, $hash) {
        if (password_verify($password, $hash)) return true;
        return false;
    }
}

As You can see this is just a simple overlay, but there is a first occasion to use it. How can I replace the password_hash and password_verify function with crypt function to be compatible in the future with passrowd_ functions?

For example. Now I will do crypt(), then store the result in users database, and in the future when I will switch to password_hash and password_verify functions, I want this crypted password to work, and not forcing every user to change password.

I hope that during my research I haven't missed anything. I'm looking for simple, elegant, SAFE solution :).

Thx for You help, br

UPDATE: I have read this (http://pl1.php.net/manual/en/function.password-hash.php):

password_hash() creates a new password hash using a strong one-way hashing algorithm. password_hash() is compatible with crypt(). Therefore, password hashes created by crypt() can be used with password_hash().

But crypt has got many options, and I;m not quite sure, if all of them are compatible.

Это было полезно?

Решение

As per OP's request:

You can use the password compatibility pack if on PHP < 5.5

This is especially useful when you wish to use PHP's 5.5 password_hash() function.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top