CKTIS / PHP
password_hash()
Genera un hash de contraseña que incluye sal, algoritmo y coste para verificarlo.
Versión: PHP 8.4; repository runtime, production runtime not attested
Sintaxis
password_hash(#[SensitiveParameter] string $password, string|int|null $algo, array $options = []): stringGenera un hash de contraseña que incluye sal, algoritmo y coste para verificarlo. PHP genera la sal automáticamente. En PHP 8.4 el coste predeterminado de bcrypt aumenta a 12. bcrypt usa como máximo los primeros 72 bytes. Compruebe con password_verify(). En PHP 8.4 PASSWORD_DEFAULT elige bcrypt. Las versiones futuras pueden cambiar el algoritmo y la longitud del hash.
Firma
password_hash(#[SensitiveParameter] string $password, string|int|null $algo, array $options = []): string
Salida del ejemplo
["bcrypt",12,true]
Ejemplos
<?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]