What is the default algorithm in password_hash What is the default algorithm in password_hash php php

What is the default algorithm in password_hash


I have had a look into the PHP source code. It defaults to bcrypt in PHP5.5.

From ext/standard/php_password.h line 31:

#define PHP_PASSWORD_DEFAULT    PHP_PASSWORD_BCRYPT


This has been updated in the documentation at password_hash() and will be updating shortly in the constants page (I just committed the documentation change about an hour or so ago).

This will be live today at password.constants

From the updated constants page (which hasn't gone live yet, but will be later today):

Available algorithms:

  • PASSWORD_BCRYPT (integer)

    PASSWORD_BCRYPT is used to create new password hashes using the CRYPT_BLOWFISH algorithm.

    This will always result in a hash using the "$2y$" crypt format, which is always 60 characters wide.

    Supported Options:

    • salt - to manually provide a salt to use when hashing the password. Note that this will override and prevent a salt from being automatically generated.

      If omitted, a random salt will be generated by password_hash() for each password hashed. This is the intended mode of operation.

    • cost - which denotes the algorithmic cost that should be used. Examples of these values can be found on the crypt() page.

      If ommitted, a default value of 10 will be used. This is a good baseline cost, but you may want to consider increasing it depending on your hardware.

  • PASSWORD_DEFAULT (integer)

    The default algorithm to use for hashing if no algorithm is provided. This may change in newer PHP releases when newer, stronger hashing algorithms are supported.

    It is worth noting that over time this constant can (and likely will) change. Therefore you should be aware that the length of the resulting hash can change. Therefore, if you use PASSWORD_DEFAULT you should store the resulting hash in a way that can store more than 60 characters (255 is the recomended width).

    Values for this constant:

    • PHP 5.5.0 - PASSWORD_BCRYPT

As far as when and how PASSWORD_DEFAULT will be updated, that's on the password_hash() documentation page:

Note: Updates to supported algorithms by this function (or changes to the default one) must follow the following rules:

  • Any new algorithm must be in core for at least 1 full release of PHP prior to becoming default. So if, for example, a new algorithm is added in 5.5.5, it would not be eligible for default until 5.7 (since 5.6 would be the first full release). But if a different algorithm was added in 5.6.0, it would also be eligible for default at 5.7.0.

  • The default should only change on a full release (5.6.0, 6.0.0, etc) and not on a revision release. The only exception to this is in an emergency when a critical security flaw is found in the current default.


The documentation is actually rather specific, if a bit poorly worded; the hash is the strongest one PHP believes it has available at the time, and is subject to change at any time. The hashes produced by password_hash contain a bit of data at the start that indicates which has was initially used to produce them, allowing such upgrades to occur automatically as new hash algorithms become available, without breaking any hashes you have already stored in a database.

Since bcrypt is the only algorithm currently defined, you can probably assume it's the default, but a quick way to verify would be to make a simple PHP script that hashes the same string twice, once with each option, and with a fixed salt, and prints the resulting hashes; they will probably match.

The original password_hash spec may also be of some help. https://wiki.php.net/rfc/password_hash