dev-master
9999999-devA password hash class
MIT
The Requires
- php >=7.0
The Development Requires
by Nathan King
v1.0
1.0.0.0A password hash class
MIT
The Requires
- php >=7.0
The Development Requires
by Nathan King
Wallogit.com
2017 © Pedro Peláez
A password hash class
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)
composer require crudle/phash, (*2)
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
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;
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);
$hash->verify('mypassword'); // throws InvalidPasswordException
$hash->needsRehash(); // throws HashValidationException
$hash->getInfo(); // returns an array of config info
$hash->__toString(); // returns the hash string
A password hash class
MIT
A password hash class
MIT