Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / PHP

hash_equals()

Confronta sequenze di byte di uguale lunghezza evitando fughe tramite il tempo di confronto.

Versione: PHP 8.4; repository runtime, production runtime not attested

Sintassi

hash_equals(string $known_string, string $user_string): bool

Confronta sequenze di byte di uguale lunghezza evitando fughe tramite il tempo di confronto. Il valore noto va per primo. Lunghezze diverse danno subito false e possono rivelare la lunghezza nota. Il testo esadecimale differisce dai byte grezzi.

Firma

hash_equals(string $known_string, string $user_string): bool

Output dell’esempio

[true,false,false]

Esempi

<?php
$expected=hash("sha256","release");
echo json_encode([hash_equals($expected,hash("sha256","release")),hash_equals($expected,hash("sha256","draft")),hash_equals($expected,hash("sha256","release",true))]);

Risultato

[true,false,false]

Fonti