Hasher
The Quantum Hasher
library make it easy to hash and verify your passwords using modern, secure and robust hashing algorithms.
To start using the library you need to make it available in your controller and create new `Hasher`
instance..
PHP
phpuse Quantum\Libraries\Hasher\Hasher;
...
$hasher = new Hasher();
...
By default the Hasher
library uses Bcrypt
algorithm with cost=12
to hash the password.
To set other algorithm you can use:
PHP
php$hasher->setAlgorithm(PASSWORD_ARGON2I);
To change the cost you can use:
PHP
php$hasher->setCost(14);
The hash($password)
method will return a hash of the provided password
PHP
php$hashed = $hasher->hash('foobar');
The check($password, $hash)
method will verifiy if the password matches to the hash
PHP
phpif($hasher->check('foobar', $hashed)) {
// matched
} else {
// not matched
}
The needsRehash($hash)
method returns true if the provided hash needs to be rehashed otherwise false will be returned
PHP
php$needsRehash = $hasher->needsRehash($hashed);
The info($hash)
method returns info about the hash
PHP
phpout($hasher->info($hashed));