PHP crypt function on different OS

In my php application, I use the php crypt () function, where my salt value is the first two characters of the username. I noticed that the function returns a different result on windows and linux. I also read about w3cschools that this feature behaves differently on different operating systems. Can I configure my php environment to get the same result on both operating systems? (Changing the encryption mode is not an option.)

+3
source share
2 answers

crypt () uses any basic hash function used by the OS, so if you want reliable (consistent) results, you can use one of the other hash functions, such as md5 () or sha256 (), sha512 () .

If you want crypt () to use the special hash function , you need to specify a hash parameter and check if the algorithm is supported on the host OS. For example (taken from the PHP Manual page crypt () ):

if (CRYPT_STD_DES == 1) {
        echo 'Standard DES: ' . crypt('rasmuslerdorf', 'rl') . "\n";
} 

But its a very dependent OS, so I recommend using a standalone hash function. Or hash () .

Append:

() hash_algos(), , , , :

<?php
    $algos = hash_algos();
    if (in_array("sha256", $algos)) {
        $pass = hash ("sha256", "userpassword" . "salt");
    }
?>

, .

+3

, , , , . PHP 5.3 , 5.3, PHP.

, vanneto, . crypt , , . blowfish, :

$2a$xx$yyyyyyyyyyyyyyyyyyyyyy

xx yyyy... (22) base64 . , vanneto (2 ), DES.

0

Source: https://habr.com/ru/post/1780375/


All Articles