phpday 2027 - Call for Papers

password_get_info

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

password_get_info — Gibt Informationen über einen Hash zurück

Beschreibung

function password_get_info(string $hash): array

Falls ein gültiger Hash übergeben wird, der durch einen von password_hash() unterstützen Algorithmus erzeugt wurde, gibt diese Funktion ein Array mit Informationen über diesen Hash zurück.

Parameter-Liste

hash

Ein Hash, der durch password_hash() erzeugt wurde.

Rückgabewerte

Gibt ein assoziatives Array mit drei Elementen zurück:

User Contributed Notes 1 note

up
11
cbungholio at gmail dot com
9 years ago
If you're curious to use this method to determine if there is someway to evaluate if a given string is NOT a password_hash() value...

<?php

// Our password.. the kind of thing and idiot would have on his luggage:
$password_plaintext = "12345";

// Hash it up, fuzzball!
$password_hash = password_hash( $password_plaintext, PASSWORD_DEFAULT, [ 'cost' => 11 ] );

// What do we get?
print_r( password_get_info( $password_hash ) );

/* returns:
Array ( 
    [algo] => 1 
    [algoName] => bcrypt  // Your server's default.
    [options] => Array ( [cost] => 11 ) 
)
*/

// What about if it's un-hashed?...
print_r( password_get_info( $password_plaintext ) );

/* returns:
Array ( 
    [algo] => 0 
    [algoName] => unknown 
    [options] => Array ( ) 
) 
*/
?>

... Looks like it's up to each of us to personally decide if it's safe to compare against the final returned array.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top