hash_pbkdf2

FunctionMisc changes in PHP 8.2

Generate a PBKDF2 key derivation of a supplied password.

PHP 5.3-5.4
PHP 5.5
Added
PHP 5.6
PHP 7
PHP 8.0
Improved
PHP 8.1
Improved
PHP 8.2
Changed
PHP 8.3
PHP 8.4
PHP 8.5
PHP 8.6

hash_pbkdf2 Function synopsis

hash_pbkdf2(
    string $algo,
    string $password,
    string $salt,
    int $iterations,
    int $length = 0,
    bool $binary = false,
    array $options = []
  ): string

Parameters

$algo

Typestring

Name of selected hashing algorithm (e.g. "sha256"). For a list of supported algorithms see hash_hmac_algos.

$password

Typestring

The password to use for the derivation.

$salt

Typestring

The salt to use for the derivation. This value should be generated randomly.

$iterations

Typeint

The number of internal iterations to perform for the derivation.

$length

OptionalTypeintDefault value0

The length of the output string. If $binary is true this corresponds to the byte-length of the derived key, if $binary is false this corresponds to twice the byte-length of the derived key (as every byte of the key is returned as two hexits).

$binary

OptionalTypeboolDefault valuefalse

When set to true, outputs raw binary data. false outputs lowercase hexits.

$options

OptionalTypearrayDefault value[]

An array of options for the various hashing algorithms. Currently, only the "seed" key is supported by the MurmurHash variants.

Return value

Typestring

Returns a string containing the derived key as lowercase hexits unless $binary is set to true in which case the raw binary representation of the derived key is returned.

Changes to the hash_pbkdf2 Function

PHP 8.2

PHP 8.1

  • Optional parameter added - #7: array $options = []
 hash_pbkdf2(
     string $algo,
     string $password,
     string $salt,
     int $iterations,
     int $length = 0,
-    bool $binary = false
+    bool $binary = false,
+    array $options = []
   ): string

PHP 8.0

  • Return type added: string
  • Parameter type added for parameter #1 ($algo): string
  • Parameter type added for parameter #2 ($password): string
  • Parameter type added for parameter #3 ($salt): string
  • Parameter type added for parameter #4 ($iterations): int
  • Parameter type added for parameter #5 ($length): int
  • Parameter default value added for position #5 ($length): 0
  • Parameter name of parameter #6 changed: $raw_output to $binary
  • Parameter type added for parameter #6 ($binary): bool
  • Parameter default value added for position #6 ($binary): false
  hash_pbkdf2(
-     $algo,
+     string $algo,
-     $password,
+     string $password,
-     $salt,
+     string $salt,
-     $iterations,
+     int $iterations,
-     $length,
+     int $length = 0,
-     $raw_output
+     bool $binary = false
-   )
+   ): string

PHP 5.5

  • Function added

hash_pbkdf2 Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported No
PHP 5.3Unsupported No