Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

crypt() not functioning as needed

Tags:

php

crypt

I'm using crypt as follows:

$pass = crypt($pass, 'd4');

for both insertion and validation of a password against a mysql table. Problem is that if the passwords are similar it generates a similar result. Is there an algorithm that guarantees different results for different passwords?


1 Answers

Use hash() and choose hashing algorithm that suits you well (if possible something stronger than MD5, but don't go all the way to SHA512 either)

On crypt()'s manual page you will find this:

The standard DES-based crypt() returns the salt as the first two characters of the output. It also only uses the first eight characters of str, so longer strings that start with the same eight characters will generate the same result (when the same salt is used).

which should explain why you get same results.

like image 68
Mchl Avatar answered Aug 20 '26 14:08

Mchl