I'm using the crypt function in PHP to hash passwords, along with salt obviously. But I'm generating my salt by calling the md5 function over the date function. And every time the user logs in the salt gets regenerated.
Is any of this bad in any way? I am still relatively new to PHP (and webdev) and I'm trying to get my security right before I deploy this code.
$salt = md5(date('m/d/Y h:i:s a'));
It is considered bad practice by many. Here are (some of) the reasons:
password_hash()
is a built in function of PHP 5.5, and a compatibility library for versions slightly older than that.How to use password_hash()
TL;DR: use
password_hash()
to generate the salt AND hash the password, no need to reinvent the wheel in a less secure fashion.Credit to be given to Hobo Sapiens for mentioning
password_hash()
first.