Change language

How to use bcrypt for hashing passwords in PHP?

The password_hash() function in PHP - it is a built-in function that is used to generate a new password hash. It uses a strong and reliable hashing algorithm. The password_hash() function is very compatible with the crypt() function. Therefore, password hashes generated by crypt() can be used with password_hash() and vice versa. The password_verify() and password_hash() functions just wrap around the crypt() function, and they make it much easier to use it exactly.Syntax:
string password_hash ($password, $algo, $options)
The following algorithms are currently supported by the password_hash() function:
  • PASSWORD_DEFAULT
  • PASSWORD_BCRYPT
  • PASSWORD_ARGON2I
  • PASSWORD_ARGON2ID
Parameters:This function takes three parameters as above and described below:
  • password:stores the user’s password.
  • algo:This is a password algorithm constant that is used continuously when designation of the algorithm to be used when hashing the password.
  • Options:is an associative array that contains options. If this is removed and not enabled, a random salt will be used and the default value will be used.
Return Value:returns a hashed password on success, or False on failure.Example :
Input: echo password_hash ("GFG @ 123", PASSWORD_DEFAULT); Output: $2y $10 $.vGA19Jh8YrwSJFDodbfoHJIOFH) DfhuofGv3Fykk1a
The following programs illustrate the passwor_hash() function in PHP:Program 1: echo password_hash ( "GFG @ 123" , PASSWORD_DEFAULT); ?> Exit:
$2y $10 $Z166W1fBdsLcXPVQVfPw / uRq1ueWMA6sLt9bmdUFz9AmOGLdM393G
Program 2: $options = [ ’cost’ = > 12, ]; echo password_hash ( " GFG @ 123 " , PASSWORD_BCRYPT, $options ); ?> Exit:
$2y $12 $jgzGJmLsUHGNjmDK98MbWe82e3CIJZuflAj6lE1I.dlyhSVfz42oq
Program 3: $timeTarget = 0.069; // 69 milliseconds $cost = 8; do { $cost ++; $start = microtime (true ); password_hash ( "test" , PASSWORD_BCRYPT, [ "cost" = > $cost ]); $end = microtime (true ); } while (( $end - $start ) < $timeTarget ); echo " The appropriate cost is: " . $cost ; ?> Exit:
The appropriate cost is: 10
Program 4: echo ’Argon2i hash:’ . password_hash ( ’GFG @ 123’ , PASSWORD_ARGON2I); ?> Exit:
Argon2i hash: $argon2i $v = 19 $m = 1024, t = 2, p = 2 $YUNvTkJBT2dEejQuUVQvRQ $+ 96jm / eISqZ7 + P9n0DrsBf25piwfnLRy2Yy1VYmb9iI
Link:/www.php.net/manual/en/function.password-hash.php>https://www.php.net/manual/en/function.password-hash.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method