I am running into some issues with my log in system. If I set my user password to 'TestPassword1234', 'TestPassword' will be accepted as the password.
After testing some more I found out that the following code will result in two identical hashes being created even though the string passed is not the same.
It is important to know that all salts used are generated by this function. One is generated per test and the same one is used to hash both strings (just like it would be when logging a user in).
function GUID() {
if (function_exists('com_create_guid') === true) { return trim(com_create_guid(), '{}'); }
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
The above function was sourced from a stack overflow question, I am not sure which.
This is not the case if the password is fundamentally changed, see below for tests.
The following snippet shows two different passwords resulting in the same hash.
$guid = GUID();
echo( crypt("TestPassword1234", $guid ) ); //455nKS7NToPuY
echo("<br />");
echo( crypt("TestPassword", $guid ) ); //455nKS7NToPuY (the same!)
This snippet shows two different passwords not resulting in the same result even though they follow a similar pattern to the above snippet
$guid = GUID();
echo( crypt("Test1234", $guid ) ); //BBWxwWzIXAOQI
echo("<br />");
echo( crypt("Test", $guid ) ); //BBhe4TjDcO5XA (different...)
I assume the problem originates from the use of the GUID function. Perhaps it is faulty or only supports a password with a max length of x. I have no idea and cannot track down the SO question I found it on.
Help is much appreciated.
password_hashinstead. You should not generate a salt yourself aspassword_hashautomatically generates a safe salt for you.password_hash, my webhost uses a version of PHP which doesn't have that function.5.2.*