I have taken the following function for bcrypt from the internet. It outputs a bycrypted password which is exactly what I am looking for. I also took a function for performing a check by using the salt but this function does not provide me with the salt.
function bcrypt_hash($password, $work_factor = 8)
{
if (version_compare(PHP_VERSION, '5.3') < 0) throw new Exception('Bcrypt requires PHP 5.3 or above');
if (! function_exists('openssl_random_pseudo_bytes')) {
throw new Exception('Bcrypt requires openssl PHP extension');
}
if ($work_factor < 4 || $work_factor > 31) $work_factor = 8;
$salt =
'$2a$' . str_pad($work_factor, 2, '0', STR_PAD_LEFT) . '$' .
substr(
strtr(base64_encode(openssl_random_pseudo_bytes(16)), '+', '.'),
0, 22
)
;
return crypt($password, $salt);
}
I need a return of the password and the salt separately. Or is there a way to pull them out of this function separately.
You can’t return multiple values from a function, but you CAN return a single data structure which contains multiple values: