PHP Hash_pbkdf2 () function

Syntax:
string hash_pbkdf2 ($algo, $pass, $salt, $itr, $len, $raw_opt)  Parameters:This function takes the six parameters mentioned above and described below.
  • $algo:This is a required parameter and is defines the selected hashing algorithm (for example, "md5", "sha256", "sha1").
  • $pass:This parameter is used to specify the password used for derivation.
  • $salt:this parameter is used for derivation and the value should be generated randomly.
  • $itr:this parameter counts the number of internal iterations.
  • $len:this parameter is used to store the length of the output string.
  • $raw_opt:if set to True, then its output will be raw binary data, and if this parameter is set to e false, then the output will be in hexadecimal lowercase letters.
Return Value:This function returns the string containing the computed message digest as lowercase. The following programs illustrate the hash_pbkdf2() function in PHP:
Program 1: $gfg = "GeeksforGeeks" ; $iterations = 142;  
// Generate a random IV using
// openssl_random_pseudo_bytes()
// random_bytes() or other
// a suitable source of randomness. $salt = openssl_random_pseudo_bytes (16);  
// Using the hash_pbkdf2 function $hash = hash_pbkdf2 ( "md5" , $gfg , $salt , $iterations , 30);  
// Show result echo $hash ; ?>
Exit:
f0ebbbf59869d76f946c4b15340761
Program 2: $gfg = "Contribute1234" ; $iterations = 100;  
// Generate a random IV using
// openssl_random_pseudo_bytes()
// random_bytes() or other
// a suitable source of randomness. $salt = openssl_random_pseudo_bytes (8);  
// Using the hash_pbkdf2 function $hash = hash_pbkdf2 ( "md5" , $gfg , $salt , $iterations , 20, false);  
// Show result echo $hash ; ?>
Exit:
715b385158045923923c
Link: http://php.net/manual/en/ function.hash-pbkdf2.php



Get Solution for free from DataCamp guru