Keine Cache-Version


Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

Rechercher une fonction PHP

password_hash

(PHP 5 >= 5.5.0, PHP 7)

password_hashErstellt einen Passwort-Hash

Beschreibung

password_hash ( string $password , int $algo [, array $options ] ) : string

password_hash() erstellt einen neuen Passwort-Hash und benutzt dabei einen starken Einweg-Hashing-Algorithmus. password_hash() ist kompatibel zu crypt(). Daher können Passwort-Hashes, die durch crypt() erzeugt wurden, mit password_hash() verwendet werden.

Die folgenden Algorithmen werden zur Zeit unterstützt:

  • PASSWORD_DEFAULT - Benutzt den bcrypt-Algorithmus (Standard in PHP 5.5.0). Beachte, dass sich diese Konstante mit der Zeit ändern wird, wenn stärkere Algorithmen in PHP implementiert werden. Aus diesem Grund kann sich die Länge des zurückgegebenen Strings mit der Zeit ändern. Es wird deshalb empfohlen das Ergebnis in einem Datenbankfeld zu speichern, das mehr als 60 Zeichen speichern kann. (z.B. 255 Zeichen).
  • PASSWORD_BCRYPT - Benutzt den CRYPT_BLOWFISH-Algorithmus zum Erstellen des Hashes. Dies erstellt einen crypt()-kompatiblen Hash und benutzt die "$2y$"-Kennung. Es wird immer ein 60 Zeichen langer String zurückgegeben, Im Fehlerfall wird FALSE zurückgegeben..
  • PASSWORD_ARGON2I - Use the Argon2i hashing algorithm to create the hash. This algorithm is only available if PHP has been compiled with Argon2 support.
  • PASSWORD_ARGON2ID - Use the Argon2id hashing algorithm to create the hash. This algorithm is only available if PHP has been compiled with Argon2 support.

Unterstützte Optionen für PASSWORD_BCRYPT:

  • salt (string) - to manually provide a salt to use when hashing the password. Note that this will override and prevent a salt from being automatically generated.

    If omitted, a random salt will be generated by password_hash() for each password hashed. This is the intended mode of operation.

    Warnung

    Die salt Option wurde von PHP 7.0.0 an missbilligt. Es wird nun empfohlen einfach das Salt zu verwenden, das standardmäßig erzeugt wird.

  • cost (integer) - which denotes the algorithmic cost that should be used. Examples of these values can be found on the crypt() page.

    If omitted, a default value of 10 will be used. This is a good baseline cost, but you may want to consider increasing it depending on your hardware.

Supported options for PASSWORD_ARGON2I and PASSWORD_ARGON2ID:

  • memory_cost (integer) - Maximum memory (in kibibytes) that may be used to compute the Argon2 hash. Defaults to PASSWORD_ARGON2_DEFAULT_MEMORY_COST.

  • time_cost (integer) - Maximum amount of time it may take to compute the Argon2 hash. Defaults to PASSWORD_ARGON2_DEFAULT_TIME_COST.

  • threads (integer) - Number of threads to use for computing the Argon2 hash. Defaults to PASSWORD_ARGON2_DEFAULT_THREADS.

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Parameter-Liste

password

Das Passwort des Benutzers.

Achtung

Die Verwendung von PASSWORD_BCRYPT als Algorithmus führt dazu, dass der password Parameter auf eine Höchstlänge von 72 Zeichen gekürzt wird.

algo

Eine Konstante für den Passwort-Algorithmus, die den Algorithmus zum hashen des Passwortes angibt.

options

Ein assoziatives Array mit Optionen. Siehe auch Konstanten für Passwort-Algorithmen für Informationen zu den von dein jeweiligen Algorithmen unterstützten Optionen.

If omitted, a random salt will be created and the default cost will be used.

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Rückgabewerte

Returns the hashed password, Im Fehlerfall wird FALSE zurückgegeben..

Der verwendete Algorithmus, der Aufwand und das Salt werden als Teil des Hashes zurückgegeben. Daher sind alle Informationen, die benötigt werden, um den Hash zu verifizieren, darin enthalten. Dies erlaubt es der Funktion password_verify() den Hash zu überprüfen, ohne dass eine separate Speicherung für das Salt oder die Algorithmus-Information erforderlich ist.

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Beispiele

Beispiel #1 password_hash() example

<?php
/**
 * We just want to hash our password using the current DEFAULT algorithm.
 * This is presently BCRYPT, and will produce a 60 character result.
 *
 * Beware that DEFAULT may change over time, so you would want to prepare
 * By allowing your storage to expand past 60 characters (255 would be good)
 */
echo password_hash("rasmuslerdorf"PASSWORD_DEFAULT);
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

$2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a

Beispiel #2 password_hash() example setting cost manually

<?php
/**
 * In this case, we want to increase the default cost for BCRYPT to 12.
 * Note that we also switched to BCRYPT, which will always be 60 characters.
 */
$options = [
    
'cost' => 12,
];
echo 
password_hash("rasmuslerdorf"PASSWORD_BCRYPT$options);
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K

Beispiel #3 password_hash() example finding a good cost

<?php
/**
 * This code will benchmark your server to determine how high of a cost you can
 * afford. You want to set the highest cost that you can without slowing down
 * you server too much. 8-10 is a good baseline, and more is good if your servers
 * are fast enough. The code below aims for ≤ 50 milliseconds stretching time,
 * which is a good baseline for systems handling interactive logins.
 */
$timeTarget 0.05// 50 Millisekunden 

$cost 8;
do {
    
$cost++;
    
$start microtime(true);
    
password_hash("test"PASSWORD_BCRYPT, ["cost" => $cost]);
    
$end microtime(true);
} while ((
$end $start) < $timeTarget);

echo 
"Appropriate Cost Found: " $cost;
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

Appropriate Cost Found: 10

Beispiel #4 password_hash() example using Argon2i

<?php
echo 'Argon2i hash: ' password_hash('rasmuslerdorf'PASSWORD_ARGON2I);
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Anmerkungen

Achtung

It is strongly recommended that you do not generate your own salt for this function. It will create a secure salt automatically for you if you do not specify one.

As noted above, providing the salt option in PHP 7.0 will generate a deprecation warning. Support for providing a salt manually may be removed in a future PHP release.

Hinweis:

It is recommended that you test this function on your servers, and adjust the cost parameter so that execution of the function takes less than 100 milliseconds on interactive systems. The script in the above example will help you choose a good cost value for your hardware.

Hinweis: Updates to supported algorithms by this function (or changes to the default one) must follow the following rules:

  • Any new algorithm must be in core for at least 1 full release of PHP prior to becoming default. So if, for example, a new algorithm is added in 7.5.5, it would not be eligible for default until 7.7 (since 7.6 would be the first full release). But if a different algorithm was added in 7.6.0, it would also be eligible for default at 7.7.0.
  • The default should only change on a full release (7.3.0, 8.0.0, etc) and not on a revision release. The only exception to this is in an emergency when a critical security flaw is found in the current default.

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Changelog

Version Beschreibung
7.3.0 Support for Argon2id passwords using PASSWORD_ARGON2ID was added.
7.2.0 Support for Argon2i passwords using PASSWORD_ARGON2I was added.

Erste Seite von PHP-Handbuch Inhaltsverzeichnis Haut

Siehe auch

Finde eine PHP-Funktion

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 30/01/2003, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/php-rf-function.password-hash.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Referenzen

  1. Zeigen Sie - html-Dokument Sprache des Dokuments:fr Manuel PHP : http://php.net

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut