0
$\begingroup$

I'm learning PHP and I've come to the password hashing section of a course I'm following, but it's not explained well enough for my liking.

It seems that when using the crypt function, and using the CRYPT_BLOWFISH hash type, I get a resultant hash that contains the salt itself.

For example with the following code:

$salt = '$2y$10$iusesomecrazystrings22';

$password = crypt($password, $salt);

And using the password "123" I get a resultant \$password of $2y$10$iusesomecrazystrings2ui1qr860E30b0c9ijNqwCSwHnHdgz.1K once hashed. My question is how is this hash not reversible, if a hacker were to obtain it, given that the salt is in the hash itself?

I know that hashes use a many-to-one input-to-output mapping, so it may be difficult to reverse the hash to the exact password used, but surely it could be reversed to one of its many collisions, so to speak. However, I know that I must be wrong but can't explain why.

$\endgroup$
5
  • 3
    $\begingroup$ Does this answer your question? Why can't I reverse a hash to a possible input? also collision resistance is not related to password hashing first- and second-preimages are related. $\endgroup$
    – kelalaka
    Nov 4, 2023 at 19:58
  • $\begingroup$ @kelalaka - The first post seems to help a bit, especially Thomas' answer. I'm still confused as to how a computer couldn't reverse-engineer a hash into a possible input that could work as a password. $\endgroup$
    – cameron6
    Nov 4, 2023 at 22:24
  • 2
    $\begingroup$ Why can't we reverse hashes? $\endgroup$
    – kelalaka
    Nov 4, 2023 at 22:34
  • $\begingroup$ @kelalaka - thanks, that helped me understand! $\endgroup$
    – cameron6
    Nov 5, 2023 at 0:49
  • $\begingroup$ @cameron6: an infinitely powerful computer could indeed find a possible input that could work as a password. But for this, if the hash is $b$-bit, and well-designed, and the actual password is un-guessable, then the best method we have is to try about $2^b$ inputs. And for large $b$ (at least 90, give or take 10) that's beyond current human capabilities. $\endgroup$
    – fgrieu
    Nov 5, 2023 at 10:43

0

Browse other questions tagged or ask your own question.