I’m having a problem in encryption using PHP crypt
Following is my code :
echo $ret = crypt('Dave@123','2ドルy10ドル$XLLl50bLyTWfjcvCAxwGRu/px2Q.LXN0fHpD1KN2CQCMx/tpL1V62');
1) When using crypt in PHP Version 5.4.22 It results:
2ドルy10ドル$XLLl50bLyTWfjcvCAxwGRu/px2Q.LXN0fHpD1KN2CQCMx/tpL1V62
2) When used with PHP Version 5.2.17 it results
25ドルnFTQHtfjVg
I want the same result as 1.
hakre
200k55 gold badges454 silver badges868 bronze badges
asked Feb 13, 2014 at 14:57
Shahid Aslam
2,5753 gold badges24 silver badges32 bronze badges
-
3Are you aware that your first result from 1) shows the second input to the crypt function? I wouldn't want to get my input as output back.Samuel– Samuel2014年02月13日 14:58:48 +00:00Commented Feb 13, 2014 at 14:58
-
@Samuel You are aware that this is intended behaviour?TimWolla– TimWolla2014年02月13日 15:09:54 +00:00Commented Feb 13, 2014 at 15:09
-
PHP 5.2 is end of live. You actually don't want that. -- -1: Only wanting sth. does not qualify as a programming question. Edit: Shame on you upvoters (:)): Even more votes than the duplicate that exists for months and has answers (!).hakre– hakre2014年05月04日 10:08:08 +00:00Commented May 4, 2014 at 10:08
-
possible duplicate of to use CRYPT_BLOWFISH on php 5.2 that doesn't support ithakre– hakre2014年05月04日 10:09:21 +00:00Commented May 4, 2014 at 10:09
2 Answers 2
The issue is the 2y blowfish prefix. It was introduced after a security issue in PHP 5.3.7 and so PHP 5.2 does not know about it, sees an invalid $salt and generates an invalid hash.
The equivalent in PHP 5.2 is 2a, but it might be affected by the mentioned security issue (I did not check).
answered Feb 13, 2014 at 15:07
TimWolla
32.9k8 gold badges67 silver badges97 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-php