2017 © Pedro Peláez
 

library phpass

PHP Password Library: Easy, secure password management for PHP

image

rych/phpass

PHP Password Library: Easy, secure password management for PHP

  • Monday, September 8, 2014
  • by rchouinard
  • Repository
  • 16 Watchers
  • 234 Stars
  • 116,189 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 29 Forks
  • 6 Open issues
  • 6 Versions
  • 6 % Grown

The README.md

PHP Password Library

The PHP Password Library is designed to ease the tasks associated with working with passwords in PHP. It is capable of generating strong cryptographic password hashes, verifying supplied password strings against those hashes, and calculating the strength of a password string using various algorithms., (*1)

This project was inspired by Openwall's portable hashing library for PHP and PassLib for Python., (*2)

Features

  • Create and verify secure password hashes with only a few lines of code.
  • Supports bcrypt and PBKDF2 out of the box.
  • Easily extend to support additional hashing methods.
  • Additional password strength component based on well-known algorithms.
  • Follows the PSR-0 standard for autoloader compatibility.

Installation

PEAR

Installing via PEAR is a simple matter of including the PEAR channel and installing the rych/PHPass package., (*3)

pear channel-discover rchouinard.github.com/pear
pear install rych/PHPass-2.1.0-alpha

Composer

Composer is an easy way to manage dependencies in your PHP projects. The PHP Password Library can be found in the default Packagist repository., (*4)

After installing Composer into your project, the PHP Password Library can be installed by adding the following lines to your composer.json file and running the Composer command line tool:, (*5)

{
  "require": {
    "rych/phpass": "2.1.0-dev"
  }
}

Usage

Hashing passwords

The library provides the ability to generate strong cryptographic hashes of user passwords using a variety of methods. Each method may be customized as needed, and may also be combined with HMAC hashing when using the base class., (*6)

Examples

Use the default bcrypt adapter:, (*7)

<?php
// Default configuration - bcrypt adapter, 2^12 (4,096) iterations
$phpassHash = new \Phpass\Hash;

Use the PBKDF2 adapter:, (*8)

<?php
// Customize hash adapter - PBKDF2 adapter, 15,000 iterations
$adapter = new \Phpass\Hash\Adapter\Pbkdf2(array (
    'iterationCount' => 15000
));
$phpassHash = new \Phpass\Hash($adapter);

Create and verify a password hash:, (*9)

<?php
// Create and verify a password hash from any of the above configurations
$passwordHash = $phpassHash->hashPassword($password);
if ($phpassHash->checkPassword($password, $passwordHash)) {
    // Password matches...
} else {
    // Password doesn't match...
}

Calculating password strength

There are many different ways to calculate the relative strength of a given password, and this library supports a few of the most common. Each method returns a number which represents the estimated entropy for the given password. It's up to the developer to determine the minimum calculated entropy to accept. Combined with a sensible password policy, this can be a valuable tool in selecting strong passwords., (*10)

Examples

Calculate a password's entropy using NIST recommendations:, (*11)

<?php
// Default configuration (NIST recommendations)
$phpassStrength = new \Phpass\Strength;

// Returns 30
$passwordEntropy = $phpassStrength->calculate('MySecretPassword');

Calculate a password's entropy using Wolfram Alpha's algorithm:, (*12)

<?php
// Custom strength adapter (Wolfram algorithm)
$adapter = new \Phpass\Strength\Adapter\Wolfram;
$phpassStrength = new \Phpass\Strength($adapter);

// Returns 59
$passwordEntropy = $phpassStrength->calculate('MySecretPassword');

The Versions

08/09 2014

dev-master

9999999-dev https://github.com/rchouinard/phpass

PHP Password Library: Easy, secure password management for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

password cryptography

28/05 2013

dev-develop

dev-develop https://github.com/rchouinard/phpass

PHP Password Library: Easy, secure password management for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

The Development Requires

password cryptography

08/09 2012

3.x-dev

3.9999999.9999999.9999999-dev https://github.com/rchouinard/phpass

PHP Password Library: Easy, secure password management for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.8
  • ext-hash *

 

security password cryptography

14/08 2012

v3.0.0beta1

3.0.0.0-beta1 https://github.com/rchouinard/phpass

PHP Password Library: Easy, secure password management for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.8
  • ext-hash *

 

security password cryptography

25/04 2012

v2.0.2-p1

2.0.2.0-patch1 http://rchouinard.github.com/phpass

PHP Password Library: Easy, secure password management for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.7

 

password cryptography

24/02 2012

v2.0.1

2.0.1.0 https://www.github.com/rchouinard/phpass

PHPass: Easy, secure password management for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.1
  • ext-hash *

 

password cryptography