hash_equals

(PHP 5 >= 5.6.0, PHP 7, PHP 8)

hash_equalsTiming attack safe string comparison

Beschreibung

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

Compares two strings using the same time whether they're equal or not.

This function should be used to mitigate timing attacks; for instance, when testing crypt() password hashes.

Parameter-Liste

known_string

The string of known length to compare against

user_string

The user-supplied string

Rückgabewerte

Returns true when the two strings are equal, false otherwise.

Fehler/Exceptions

Emits an E_WARNING message when either of the supplied parameters is not a string.

Beispiele

Beispiel #1 hash_equals() example

<?php
$expected  
crypt('12345''$2a$07$usesomesillystringforsalt$');
$correct   crypt('12345''$2a$07$usesomesillystringforsalt$');
$incorrect crypt('apple''$2a$07$usesomesillystringforsalt$');

var_dump(hash_equals($expected$correct));
var_dump(hash_equals($expected$incorrect));
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

bool(true)
bool(false)

Anmerkungen

Hinweis:

Both arguments must be of the same length to be compared successfully. When arguments of differing length are supplied, false is returned immediately and the length of the known string may be leaked in case of a timing attack.

Hinweis:

It is important to provide the user-supplied string as the second parameter, rather than the first.

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

ytotec Snabb leverans. Köp Cytotec Online Fedex - köp Cytotec inget recept. Umeå – S

Snabb leverans Cytotec. Köp Cytotec Online Fedex Behöver du pålitliga, högkvalitativa mediciner, men vill inte lämna hemmet för att köpa de ...

Geschrieben von travelder am 19.06.2026 20:57:48
Forum: Bücher-Forum
evia Buy anonymously. Revia cheap order - Pharmacy Brand Revia. Leeds — United Kingd

Buy anonymously Revia. Revia cheap order Looking for top-notch meds without leaving home? Look no further! Our trusted online store has got you co ...

Geschrieben von drawer am 19.06.2026 20:57:43
Forum: Ankündigungen
rmodafinil Kopen. Koop de volgende dag Armodafinil online - Armodafinil Koop ons AME

Kopen Armodafinil. Koop de volgende dag Armodafinil online Op zoek naar eersteklas medicijnen zonder dat u uw huis hoeft te verlaten? Zoek niet ve ...

Geschrieben von travelder am 19.06.2026 20:57:16
Forum: Projekthilfe
ylenol Precio. comprar Tylenol 0 5mg online - comprar Tylenol Europa. Málaga — Españ

Precio Tylenol. comprar Tylenol 0 5mg online ¿Necesita medicamentos de calidad sin complicaciones? ¡Nuestra farmacia en línea está aquí para ...

Geschrieben von travelder am 19.06.2026 20:56:11
Forum: Entwicklungsumgebungen