2017 © Pedro Peláez
 

library password-compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash

image

ircmaxell/password-compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash

  • Monday, March 20, 2017
  • by ircmaxell
  • Repository
  • 152 Watchers
  • 2028 Stars
  • 26,144,282 Installations
  • PHP
  • 233 Dependents
  • 26 Suggesters
  • 405 Forks
  • 15 Open issues
  • 8 Versions
  • 4 % Grown

The README.md

password_compat

Build Status Code Climate, (*1)

This library is intended to provide forward compatibility with the password_* functions that ship with PHP 5.5., (*2)

See the RFC for more detailed information., (*3)

Requirements

This library requires PHP >= 5.3.7 OR a version that has the $2y fix backported into it (such as RedHat provides). Note that Debian's 5.3.3 version is NOT supported., (*4)

The runtime checks have been removed due to this version issue. To see if password_compat is available for your system, run the included version-test.php. If it outputs "Pass", you can safely use the library. If not, you cannot., (*5)

If you attempt to use password-compat on an unsupported version, attempts to create or verify hashes will return false. You have been warned!, (*6)

The reason for this is that PHP prior to 5.3.7 contains a security issue with its BCRYPT implementation. Therefore, it's highly recommended that you upgrade to a newer version of PHP prior to using this layer., (*7)

Installation

To install, simply require the password.php file under lib., (*8)

You can also install it via Composer by using the Packagist archive., (*9)

Usage

Creating Password Hashes, (*10)

To create a password hash from a password, simply use the password_hash function., (*11)

    $hash = password_hash($password, PASSWORD_BCRYPT);

Note that the algorithm that we chose is PASSWORD_BCRYPT. That's the current strongest algorithm supported. This is the BCRYPT crypt algorithm. It produces a 60 character hash as the result., (*12)

BCRYPT also allows for you to define a cost parameter in the options array. This allows for you to change the CPU cost of the algorithm:, (*13)

    $hash = password_hash($password, PASSWORD_BCRYPT, array("cost" => 10));

That's the same as the default. The cost can range from 4 to 31. I would suggest that you use the highest cost that you can, while keeping response time reasonable (I target between 0.1 and 0.5 seconds for a hash, depending on use-case)., (*14)

Another algorithm name is supported:, (*15)

    PASSWORD_DEFAULT

This will use the strongest algorithm available to PHP at the current time. Presently, this is the same as specifying PASSWORD_BCRYPT. But in future versions of PHP, it may be updated to use a stronger algorithm if one is introduced. It can also be changed if a problem is identified with the BCRYPT algorithm. Note that if you use this option, you are strongly encouraged to store it in a VARCHAR(255) column to avoid truncation issues if a future algorithm increases the length of the generated hash., (*16)

It is very important that you should check the return value of password_hash prior to storing it, because false or null may be returned if it encountered an error., (*17)

Verifying Password Hashes, (*18)

To verify a hash created by password_hash, simply call:, (*19)

    if (password_verify($password, $hash)) {
        /* Valid */
    } else {
        /* Invalid */
    }

That's all there is to it., (*20)

Rehashing Passwords, (*21)

From time to time you may update your hashing parameters (algorithm, cost, etc). So a function to determine if rehashing is necessary is available:, (*22)

    if (password_verify($password, $hash)) {
        if (password_needs_rehash($hash, $algorithm, $options)) {
            $hash = password_hash($password, $algorithm, $options);
            /* Store new hash in db */
        }
    }

Security Vulnerabilities

If you have found a security issue, please contact the author directly at ircmaxell@php.net., (*23)

The Versions

20/03 2017

dev-master

9999999-dev https://github.com/ircmaxell/password_compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash

  Sources   Download

MIT

The Development Requires

password hashing

20/11 2014

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/ircmaxell/password_compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash

  Sources   Download

MIT

The Development Requires

password hashing

20/11 2014

v1.0.4

1.0.4.0 https://github.com/ircmaxell/password_compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash

  Sources   Download

MIT

The Development Requires

password hashing

30/04 2013

1.0.3

1.0.3.0 https://github.com/ircmaxell/password_compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash

  Sources   Download

MIT

password hashing

30/04 2013

1.0.2

1.0.2.0 https://github.com/ircmaxell/password_compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash

  Sources   Download

MIT

password hashing

30/04 2013

1.0.1

1.0.1.0 https://github.com/ircmaxell/password_compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash

  Sources   Download

MIT

password hashing

14/01 2013

1.0.0

1.0.0.0 https://github.com/ircmaxell/password_compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash

  Sources   Download

MIT

password hashing

18/09 2012

dev-nicholas-grekas-xor-fix

dev-nicholas-grekas-xor-fix https://github.com/ircmaxell/password_compat

A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash

  Sources   Download

MIT

The Requires

  • php >= 5.3.7

 

password hashing