As @Nambi suggested if you are going to use crypt() you will need to use the optional parameter Salt, otherwise it will return different results, that's why it's never matching.
echo crypt('foo');
echo crypt('foo');
echo crypt('foo');
returns:
$1$rnmZxKr0$V7lk8JZ0tV1Utb78hH0g.0
$1$v84YR6KA$Xl5QvouObIZqWvxEIQwO/.
$1$expSZHgb$HAZ9ydKmjQcmwLeLDxjO41
echo crypt('foo', 'bar');
echo crypt('foo', 'bar');
echo crypt('foo', 'bar');
returns:
ba4TuD1iozTxw
ba4TuD1iozTxw
ba4TuD1iozTxw
Obviously it would be good to obscure the salt instead of having a plain one or let it autogenerate if you want more control.
When registering the user you have to store the generated salt.
When checking the login, you get the salt, and use it with the user input password to crypt() it, and check if the crypted password with that salt matches the one in the database.
Notes: For security, it's obvious but just in case: generate a differente salt for each password, if you use the same salt, if one password is hacked then the hacker will know the salt for all the other passwords, making his life easier.
And as @Nabil suggested you better research a bit what encryption you will use, because later on will be pain in the a** to change it.
Personally I like blowfish
Avoid MD5 and SHA1, they were considered safe once, but it is not anymore as the technology evolved, even on the respective pages on the php documentation users warn newer users not to use them.