CKTIS / PHP
password_hash()
Cria um hash da palavra-passe que inclui o sal, o algoritmo e o custo para verificação.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
password_hash(#[SensitiveParameter] string $password, string|int|null $algo, array $options = []): stringCria um hash da palavra-passe que inclui o sal, o algoritmo e o custo para verificação. O PHP gera o sal automaticamente. Em PHP 8.4 o custo predefinido do bcrypt sobe para 12. O bcrypt usa no máximo os primeiros 72 bytes. Verifique com password_verify(). Em PHP 8.4 PASSWORD_DEFAULT escolhe bcrypt. Versões futuras podem alterar o algoritmo e o comprimento do hash.
Assinatura
password_hash(#[SensitiveParameter] string $password, string|int|null $algo, array $options = []): string
Saída do exemplo
["bcrypt",12,true]
Exemplos
<?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)]);
Resultado
["bcrypt",12,true]