php - Different passwords generating same encryption using crypt() function -
this question has answer here:
i using php's crypt() function encrypt password before storing database.now if password contains number passwords same sub string generates same encryption. example below passwords generate same encryption.
echo crypt('abcdefg123','mykey').'<br>'; echo crypt('abcdefg123','mykey').'<br>'; echo crypt('abcdefg123456','mykey').'<br>';
encrypted password result is
myewt99ku6tam
what doing wrong? or bug?
crypt
function takes salt
second argument. salt
has special formats described here.
have provided salt
recognized standard des algorithm.
the standard des-based crypt() returns salt first 2 characters of output. it uses first 8 characters of str, longer strings start same 8 characters generate same result (when same salt used).
provide proper salt. example, try md5:
echo crypt('abcdefg123','$1$mykeyabcd$').'<br>'; echo crypt('abcdefg123','$1$mykeyabcd$').'<br>'; echo crypt('abcdefg123456','$1$mykeyabcd$').'<br>';
Comments
Post a Comment