What I'm about to say is probably going to make me look like an idiot but it's better to be wrong and learn than have unanswered questions.
Ever since I started dealing with passwords I wondered what the big fuss about hashing passwords is anyway, since if somebody got a hold of your database they could find out any password no matter what hashing technique is used.
So basically the big flaw of old hashing functions were rainbow tables, something that the currently modern algorithm used by PHP in their password hashing API, blowfish, deals with. Of course it is pretty complex and undoubtedly it's built by people way smarter than me, but still I just couldn't help but wonder, if I built my own hashing function that wasn't vulnerable to rainbow tables and didn't store the salt in obvious places such as extra columns in the database or use user information like name or email as salt, would that be any good?
I just spent like 5 minutes to prepare this example for you, which uses, of course, md5, as I know it is the most hated around PHP developer critics :D
function my_password_hash($password){
$salt = substr(md5(str_shuffle('0123456789abcdef')), 0, 5);
$hash = substr(md5($password . $salt), 0, -5) . $salt;
return $hash;
}
function my_password_check($password, $hash){
$salt = substr($hash, -5);
return substr(md5($password . $salt), 0, -5) . $salt === $hash;
}
$hash = my_password_hash('qwerty');
var_dump(my_password_check('qwerty', $hash)); // TRUE
var_dump(my_password_check('qwertY', $hash)); // FALSE
It will produce different hashes for the same input every time and the salt is blended in the final output hash, if you don't explicitly know where it is, I don't think it can be found, but that's why I'm posting here, to find out if I'm wrong.