Php blowfish hashing with crypt (): CLI result differs from webserver one

When I use the php crypt () function using Blowfish algorithm with webserver :


    echo crypt('SAD123', sprintf('$2a$10$%s', '7711cbpe58dfpogiu049857f011werb0'));


I get this result:



But if I use the command line PHP interpreter :

php -r "echo crypt('SAD123', sprintf('$2a$10$%s', '7711cbpe58dfpogiu049857f011werb0'));"


I am getting the following output:



Do you have any ideas?

System: Apache / 2.2.3 (CentOS), PHP 5.4.26


source to share

1 answer

This is because dollar signs followed by digits on the command line are also interpreted as positional parameters in bash.

When you leave them, it will work as expected:

$ php -r "echo crypt('SAD123', sprintf('\$2a\$10$%s', '7711cbpe58dfpogiu049857f011werb0'));"


So, if you want to tinker with some PHP on your line, you should just run it interactively:

$ php -a
php > echo crypt('SAD123', sprintf('$2a$10$%s', '7711cbpe58dfpogiu049857f011werb0'));




All Articles