CKTIS / PHP
password_hash()
Create a salted password hash carrying its algorithm and cost for later verification.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
password_hash(#[SensitiveParameter] string $password, string|int|null $algo, array $options = []): stringCreate a salted password hash carrying its algorithm and cost for later verification. PHP generates the salt automatically. PHP 8.4 raises the default bcrypt cost to 12. Bcrypt uses at most the first 72 bytes of a password. Compare a candidate with password_verify(). PASSWORD_DEFAULT selects bcrypt in PHP 8.4. A future version may change the algorithm and the length of its encoded hash.
Signature
password_hash(#[SensitiveParameter] string $password, string|int|null $algo, array $options = []): string
Example output
["bcrypt",12,true]
Examples
<?php
$hash=password_hash("maple notes",PASSWORD_DEFAULT);
echo json_encode([password_get_info($hash)["algoName"],password_get_info($hash)["options"]["cost"],password_verify("maple notes",$hash)]);
Result
["bcrypt",12,true]