|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-03-12 10:54 UTC] jerome dot auge at anakeen dot com
Description:
------------
I use crypt() to store and validate passwords using the « Standard DES » hash, and after upgrading to 5.3.2, the hashed password of an account is not the same as the one generated with PHP 5.3.1 :
With PHP 5.3.1 :
$ php -r 'print crypt("anakeen", "A^")."\n";'
A^1ul2Jf7VS2M
After upgrading to PHP 5.3.2 :
$ php -r 'print crypt("anakeen", "A^")."\n";'
A^/ImZ5hqd2VU
I tested both on Mac (macports) and on Linux (rawhide), and the hash result was different on both platform.
On Mac OS X (10.5), the Perl (or C) crypt gives me the same results as PHP 5.3.1 :
$ perl -e 'print crypt("anakeen", "A^")."\n";'
A^1ul2Jf7VS2M
While on Linux, the Perl script gives me the same result as PHP 5.3.2.
It appears that there is a difference in the crypt() function, between these platforms, regarding the presence of non alpha-num chars in the salt :
Mac OS X with "A-" salt = different hashes :
$ php -r 'print crypt("anakeen", "A-")."\n";'
A-75An91LCLEM
$ perl -e 'print crypt("anakeen", "A-")."\n"';
A-1ul2Jf7VS2M
Mac OS X with "A9" salt = same hashes :
$ perl -e 'print crypt("anakeen", "A9")."\n"';
A9Pf3.gAayQMM
$ php -r 'print crypt("anakeen", "A9")."\n";'
A9Pf3.gAayQMM
Maybe I should not have used non alpha-num chars for my salt in the first place ?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 16:00:01 2025 UTC |
I have a similar problem going from PHP 5.2.8 to 5.3.0. <?php if(CRYPT_STD_DES == 1) { echo "Standard DES is available.\n\n"; } $username = 'aardvark'; $password = 'password'; $salt = substr($username, 0, 1); echo "\$salt = $salt\n"; $pass = crypt($password, $salt); echo "Standard crypt encryption (1 char salt) = '$pass'\n"; $des_pass = crypt($password, 'a$'); echo "DES encryption (2 char salt) = '$des_pass'\n"; ?> Output from PHP 5.3.0: $ php test24.php Standard DES is available. $salt = a Standard crypt encryption (1 char salt) = 'a$Av8awQ0AsR6' DES encryption (2 char salt) = 'a$Av8awQ0AsR6' Output of the same code on PHP 5.2.8: $ php test24.php Standard DES is available. $salt = a Standard crypt encryption (1 char salt) = 'a$LHSkrbhfU1.' DES encryption (2 char salt) = 'a$LHSkrbhfU1.'You are correct. When I switched to using a two character alpha-numeric salt, both PHP 5.2.8 and 5.3.0 returned the same encrypted string. However, if I use a one character alpha-numeric salt, I get a different result on PHP 5.2.8 and 5.3.0: <?php $password = 'password'; $salt = 'a'; $des_pass = crypt($password, $salt); echo "DES encryption (salt = $salt) = $des_pass\n"; ?> PHP 5.2.8: $ php test27.php DES encryption (salt = a) = a$LHSkrbhfU1. PHP 5.3.0: $ php test27.php DES encryption (salt = a) = a$Av8awQ0AsR6 I wouldn't ordinarily break the rules, so-to-speak, by using a one character salt, but I'm trying to match an encryption created by a one character salt. Is this also producing undefined behavior because of the shortness of the salt? Thanks