How can I extract the salt out of bcrypt hash passwords in php? How can I extract the salt out of bcrypt hash passwords in php? php php

How can I extract the salt out of bcrypt hash passwords in php?


You need to use the password_verify function. This function will parse the hashed password string to find the salt and perform the calculation.

if (password_verify($data['form-password'], $user->getPasswordHash())) {    echo 'Password is correct';}


Salt is the first 22 characters after the third $ in the hash:

$2y$13$<this is the salt, 22 chars><this is the password hash>

But you should not manually extract the salt to verify the password - use the password_verify function. It takes the password the user entered as the first argument, and the complete hash as the second argument, and handles the salt correctly.