passwords

PHP Logo

PHP Password Functions In 5.5

4th March 2014 - 5 minutes read time

New in PHP 5.5 is a group of functions that deal with password hashing and verification. This is such a common thing for PHP applications to do that it was decided to include it into the core of PHP. They effectively solve the problem of hashing and comparing passwords that just about every PHP developer has implemented at one point or another.

There are only a few functions available but they provide all of the functionality needed to create a hash value from a password, check if the hash is valid and to check if the password hash needs to be recreated.

To create a hash value from a password use the password_hash() function. The first parameter is the password string and the second value is the hashing algorithm to use. The value PASSWORD_DEFAULT here is a PHP constant that is currently set to the bcrypt algorithm and will be changed to better algorithms when and if they are found in newer versions of PHP.