I already know how to use password_verify and password_hash functions, but I don't really understand how they work.
When I use them I do something like that:
$save_hash = password_hash( $password, PASSWORD_DEFAULT ); $check = password_verify( $password, $hash );
How password_verify can know the algorithm used, the salt and the cost? The PHP official documentation say this:
Note that password_hash() returns the algorithm, cost and salt as part of the returned hash. Therefore, all information that's needed to verify the hash is included in it. This allows the verify function to verify the hash without needing separate storage for the salt or algorithm information.
But I don't really understand why all that information is included in the hash, so a possibly attacker will know too. So, if attackers know the salt, why is it secure? They only have to put the salt at the beginning and try a brute force attack the same way they would do without a salt. What am I wrong about?