• PHP Video Tutorials

PHP - password_hash Function



The password_hash() function can create a password hash.

Syntax

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

The password_hash() function can create a new password hash using a strong one-way hashing algorithm. The password_hash() function is compatible with crypt() function, therefore, password hashes created by crypt() function can be used with password_hash() function.

Example 1

<?php	
   $passw01 = "53nh46u74m3nt3";
   $opts03 = [ "cost" => 15 ];
   $hashp03 = password_hash($passw01, PASSWORD_BCRYPT, $opts03);

   echo strlen($hashp03) . " characters<br>" . $hashp03;
?> 

Output

60 characters<br>$2y$15$OyVvzp9NzC7b0x5DHczGzOE2yeyGMdr6.sSszl6X.TZBEdAtyBSGO 

Example

<?php
   $passw01 = "53nh46u74m3nt3";

   $opts04 = [ "cost" => 15, "salt" => "salteadoususuueyryy28yyGGtttwqtwtt" ];
   $hashp04 = password_hash($passw01, PASSWORD_BCRYPT, $opts04);

   echo strlen($hashp04) . " characters
" . $hashp04; ?>

Output

60 characters
$2y$15$salteadoususuueyryy28u48viMdUKIwgSc.ETLYvODrrv3MFczPq
php_function_reference.htm
Advertisements