0

Password encryption with PHP 5.5 password hashing api

Password encryption with PHP 5.5 password hashing api

Password encryption with PHP 5.5 password hashing api.Encrypting passwords using bcrypt method is the best, but a number of peoples and developers still use the older and weaker encryption algorithms like MD5 and custom salt encryption. i never recommend MD5 password encryption because their are number of online websites available which decrypt MD5 encrypted password.

Now PHP 5.5 come with a password hashing api which have number of functions that we use to generate secure password. In this article i will explain you how you use the password hashing api for encrypting password.

The new password hashing API exposes four simple functions:

  • password_hash() – used to hash the password.
  • password_verify() – used to verify a password against its hash.
password_hash()

password_hash() is one of PHP5.5 function to create strongest password hash. this algorithms is also compatible with crypt(). It generate random salt for each password hashed and it always returns the hash password or FALSE on failure.

Code to encrypt password

The first parameter of the function is the string that needs to be encrypted. Second parameter define the algorithm that should be used for generating the hashing. Third parameter is for custom options like custom salt, cost etc, it contain an array of options.

password_verify()

Now the Question is that every time different password is generated then how we will verify the password. For that password_verify() method we use the verify the hash password.

Code to check password

How to use in previous Php versions
So if you want to use these functions in older php version before 5.5 you just need to include the password_compact (library) and enjoy.

Sandeep Kumar

Sandeep kumar is a web developer and a professinal blogger. He works for latest technologies and write articles what he learn. In ICodeHub he share web languages tutorials and other programming tips and tricks. if you need some help or have some suggestion then mail him at sandeep92pal@gmail.com without any hesitation. He believes in learning and sharing.