rounds = $rounds; if ( ! function_exists('openssl_random_pseudo_bytes')) { throw new \Exception("The openssl PHP extension is required to perform bcrypt hashing."); } } /** * Perform a one-way hash on a string using bcrypt. * * @param string $value * @return string */ public function hash($value) { $salt = sprintf('$2a$%02d$', $this->rounds).substr(base64_encode(openssl_random_pseudo_bytes(16)), 0, 22); return crypt($value, str_replace('+', '.', $salt)); } /** * Determine if an unhashed value matches a given hash. * * @param string $value * @param string $hash * @return bool */ public function check($value, $hash) { return crypt($value, $hash) === $hash; } }