php - Different passwords generating same encryption using crypt() function -


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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -