CKTIS / PHP
PASSWORD_BCRYPT
PASSWORD_BCRYPT explicitly selects bcrypt for password_hash.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
password_hash($password, PASSWORD_BCRYPT)PASSWORD_BCRYPT explicitly selects bcrypt for password_hash. The resulting hash encodes the algorithm, a random salt and its cost, allowing password_verify to check a candidate without separately storing them. PHP 8.4 uses a default bcrypt cost of 12. Bcrypt considers only the first 72 bytes of input, so equal prefixes at that boundary can verify identically.
$base = str_repeat("x", 72);
$stored = password_hash($base . "A", PASSWORD_BCRYPT);
echo json_encode([
password_get_info($stored)["algoName"],
password_get_info($stored)["options"]["cost"],
password_verify($base . "A", $stored),
password_verify($base . "B", $stored),
password_verify("short", $stored)
]);
["bcrypt",12,true,true,false]
Examples
<?php
$base = str_repeat("x", 72);
$stored = password_hash($base . "A", PASSWORD_BCRYPT);
echo json_encode([
password_get_info($stored)["algoName"],
password_get_info($stored)["options"]["cost"],
password_verify($base . "A", $stored),
password_verify($base . "B", $stored),
password_verify("short", $stored)
]);
Result
["bcrypt",12,true,true,false]