Everyone knows and understands that storing the password in a clear text in the database is a quite rude thing and not secure. Yet, several do it because it makes an internet site quite easy for password recovery or testing.
The bcrypt is a password hashing technique used to build password security. It is used to protect the password from hacking attacks because of the password is stored in bcrypted format.
The password_hash() function in PHP is an inbuilt function which is used to create a new password hash. It uses a strong & robust hashing algorithm. The password_hash() function is very much compatible with the crypt() function. Therefore, password hashes created by crypt() may be used with password_hash() and vice-versa. The functions password_verify() and password_hash() just the wrappers around the function crypt(), and they make it much easier to use it accurately.
string password_hash( $password, $algo, $options )
The following algorithms are currently supported by password_hash() function:
Parameters: This function accepts three parameters as mentioned above and described below:
- password: It stores the password of the user.
- algo: It is the password algorithm constant that is used continuously while denoting the algorithm which is to be used when the hashing of password takes place.
- options: It is an associative array, which contains the options. If this is removed and doesn’t include, a random salt is going to be used, and the utilization of a default cost will happen.
Return Value: It returns the hashed password on success or False on failure.
Input : echo password_hash("GFG@123", PASSWORD_DEFAULT); Output : $2y$10$.vGA19Jh8YrwSJFDodbfoHJIOFH)DfhuofGv3Fykk1a
Below programs illustrate the passwor_hash() function in PHP:
The appropriate cost is: 10
Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YUNvTkJBT2dEejQuUVQvRQ$+96jm/eISqZ7+P9n0DrsBf25piwfnLRy2Yy1VYmb9iI
- How to secure database passwords in PHP?
- How to Secure hash and salt for PHP passwords ?
- How to encrypt and decrypt passwords using PHP ?
- Saving What Saves Our Passwords – Two-Factor Authentication
- Applications of Hashing
- Address Calculation Sort using Hashing
- Password Hashing with MD5 module in Node.js
- What is the use of the @ symbol in PHP?
- How to use a switch case 'or' in PHP?
- What is the use of “=>” symbol in PHP ?
- When to use static vs instantiated classes in PHP?
- How to use PHP OPCache ?
- How to use php serialize() and unserialize() Function
- When to use self over $this in PHP ?
- Why require_once() function is so bad to use in PHP ?
- Why use Guzzle Instead of cURL in PHP ?
- What is the use of number after “break” or “continue” statements in PHP ?
- How to use SQLMAP to test a website for SQL Injection vulnerability
- How to use animation on favicon image ?
- Use of Shopify Apps
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.