2017 © Pedro Peláez
 

library phash

A password hash class

image

crudle/phash

A password hash class

  • Monday, December 5, 2016
  • by crudle-apps
  • Repository
  • 2 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Overview

Crudle\Phash provides a convenient wrapper class for the native password_hash functions. The primary benefit of this is the ability to remain object oriented., (*1)

Install

composer require crudle/phash, (*2)

Usage

The simplest usage of PasswordHash is indeed that; simple!, (*3)

$hash = new PasswordHash('mypassword');

The string 'mypassword' will be hashed and stored in the object. If you provide an already hashed string, the value will just be stored and no hashing will occur., (*4)

// This works too! This is the hash that was generated from 'mypassword'
$hash = new PasswordHash('$2y$10$F4L/hmnkYOSvGqU0tI4DuuszxFarOedNQA1Ws.ZHwKcRLmUlWaDTW');

Once you've created the PasswordHash object (either from a raw password or a hashed string), you can perform all the native operations on it:, (*5)

$hash = new PasswordHash('$2y$10$F4L/hmnkYOSvGqU0tI4DuuszxFarOedNQA1Ws.ZHwKcRLmUlWaDTW');
$hash->verify('mypassword'); // Throws an InvalidPasswordException if validation fails

Retrieving the hash

Hashing a password is pretty useless unless we can store it for later validation. Thankfully, we can just cast the object to a string and we'll get our hash., (*6)

$passwordHash = new PasswordHash('mypassword');
$hash = (string) $passwordHash;

Extra config

By default, the package uses the PASSWORD_DEFAULT hashing algorithm. If you want to change that, or any hashing options, you can provide a custom Config object to the PasswordHash constructor., (*7)

$config = new Config(PASSWORD_BCRYPT, ['cost' => 12]);
$hash = new PasswordHash('mypassword', $config);

Available methods

$hash->verify('mypassword'); // throws InvalidPasswordException
$hash->needsRehash(); // throws HashValidationException
$hash->getInfo(); // returns an array of config info
$hash->__toString(); // returns the hash string

The Versions

05/12 2016

dev-master

9999999-dev

A password hash class

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Nathan King

05/12 2016

v1.0

1.0.0.0

A password hash class

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Nathan King