password_hash() : One way Password hash

$str="plus2net.com";
$str_hash=password_hash($str,PASSWORD_DEFAULT);
echo $str_hash;
Output is here
$2y$10$/r1bsR9lXZ52gYPmeH69Bu3.k0ABji7ZJdiZTPmUWEAgaQpkBkfKq
Syntax
password_hash('$string',$alog,$options);
ParameterDESCRIPTION
$stringRequired : Input password string variable
$alogRequired : algorithms to be used.
$options Optional : An associative array containing options.

Algorithms supported

PASSWORD_DEFAULT : bcrypt algorithm. Output length is more than 60 so better to use 255 chars
PASSWORD_BCRYPT : CRYPT_BLOWFISH to create the hash. Output 60 chars legth
PASSWORD_ARGON2I : Argon2i hashing algorithm
PASSWORD_ARGON2ID : Argon2id hashing algorithm

Example using options ( Optional )

salt : has to be minimum 22 char length. If not given then default salt will be used. Salt option is removed in PHP 7.0 so better not to use salt and allow PHP to use default salt.

cost : default value 10 .This is the algorithm cost which depends on hardware.
$str="plus2net.com";
$options =array('cost' => 12,'salt'=>'my_salt_of_22_legth_ok');
$str_hash=password_hash($str,PASSWORD_DEFAULT,$options);
echo $str_hash;
Output is here
$2y$12$bXlfc2FsdF9vZl8yMl9sZOXWXRIfffjBg.Qk195t1LcqrI2JBjIUW
No Salt Better not to use Salt and allow PHP to use its default salt as this is deprecated in PHP 7.0.0
As seen from above we can use different algorithms with password_hash(), we can store the password in our database table with length 255 chars. Next we will learn how to match the stored password against user entered password by using password_verify()
String Functions password_verify(): To match the password with user entered password mcrypt() function to work with different encryptions
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer