crypt() in PHP 5.2.8 vs PHP 5.3.0

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PP133
Forum Newbie
Posts: 1
Joined: Sun Mar 28, 2010 2:02 am

crypt() in PHP 5.2.8 vs PHP 5.3.0

Post by PP133 »

Hey guys, first post here, I'm hoping you can help me out.

Basically, I have two servers, one runs PHP 5.3.0 and one runs PHP 5.2.8. On each of those servers, the crypt function returns a different encrypted string, when given the same salt and input. This is causing some problems as a tool I'm developing, on the server running 5.3.0, is attempting to authenticate logins through a database whose passwords were created using the crypt function in PHP 5.2.8.

Here's the code that I'm running on both servers:

<?php
$username = 'aardvark';
$password = 'password';
$salt = substr($username, 0, 1);
$pass = crypt($password, $salt);
echo "\$pass = $pass\n";
?>

Here's the output on the 5.3.0 server:

$ php test23.php
$pass = a$Av8awQ0AsR6


And here's the output on the 5.2.8 server:

$ php test23.php
$pass = a$LHSkrbhfU1.


Now, if there's no other way about this, I can downgrade my PHP to 5.2.8 to play nice with the other server, but it seems odd to me that the crypt function would be upgraded, which it appears to have been for 5.3.0 and 5.3.2, but not be made backwards compatible. I guess what I'm asking here is whether there's some argument that I can give crypt so that it'll work like it did in PHP 5.2.8 from within PHP 5.3.0.

Thanks in advance.
Post Reply