Open In App

PHP | hash_pbkdf2() Function

The hash_pbkdf2() function is an inbuilt function in PHP which is used to generate a PBKDF2 key derivation of a supplied password.

Syntax:



string hash_pbkdf2( $algo, $pass, $salt, $itr, $len, $raw_opt )

Parameters: This function accept six parameters as mention above and describe below.

Return Value: This function returns the string containing the calculated message digest as lowercase hexits.



Below programs illustrate the hash_pbkdf2() function in PHP:
Program 1:




<?php
$gfg = "GeeksforGeeks";
$iterations = 142;
  
// Generate a random IV using 
// openssl_random_pseudo_bytes()
// random_bytes() or another 
// suitable source of randomness.
$salt = openssl_random_pseudo_bytes(16);
  
// Using hash_pbkdf2 function
$hash = hash_pbkdf2("md5",
    $gfg, $salt, $iterations, 30);
  
// Display result
echo $hash;
?>

Output:
f0ebbbf59869d76f946c4b15340761

Program 2:




<?php
$gfg = "Contribute1234";
$iterations = 100;
  
// Generate a random IV using 
// openssl_random_pseudo_bytes()
// random_bytes() or another 
// suitable source of randomness.
$salt = openssl_random_pseudo_bytes(8);
  
// Using hash_pbkdf2 function
$hash = hash_pbkdf2("md5",
    $gfg, $salt, $iterations, 20, false);
  
// Display result
echo $hash;
?>

Output:
715b385158045923923c

Reference: http://php.net/manual/en/function.hash-pbkdf2.php


Article Tags :