I understand how to write PHP code to successfully utilize BCrypt. So, I don't need help getting it to work.
Instead, I need help understanding how in the heck BCrypt magically works!
In this code, on line 15, in order to verify if the login password == the original (and now hashed/salted) password, it looks to me like you are just (a) creating a new hashed/salted value using the login password and the original (and now hashed/salted) password, and then (b) comparing the value created in (a) to the original (and now hashed/salted) password. I don't understand how these can ever be equal, but they are!
For example, let's say a user signs up with a password of test, which let's say (for simplicity) gets hashed/salted to 1234.
A day later, the user tries to login (using 1234), and we need to authenticate them. To do so, we execute the code on line 15. This means that we do the following:
crypt("test", "1234") == "1234"
How in the heck does hashing/salting test with a NEW SALT VALUE (in this case 1234) result in a match?
At this point, this question is mostly just a brain teaser for me. ;)