The HashLib
library provides a convenient and flexible way to generate, hash, and validate passwords with various
options and requirements. It includes a trait named Hasher
that defines password generation, validation, and
requirement checking functionalities.
The HashLib
library is designed to simplify password hashing and verification in PHP applications. It offers a trait
called Hasher
that can be easily incorporated into your own classes to handle password-related operations.
The library can be installed using Composer:
composer require tal7aouy/hashlib
use Tal7aouy\HashLib\HashLib;
$passwordHash = HashLib::getInstance();
$password = "my_secure_password";
$hashedPassword = $passwordHash::hash($password);
if ($passwordHash::verify($password, $hashedPassword)) {
echo "Password is verified!";
} else {
echo "Password verification failed.";
}
use Tal7aouy\HashLib\HashLib;
$passwordHash = HashLib::getInstance();
$password = "my_secure_password";
$hashedData = $passwordHash::hashWithSalt($password);
if ($passwordHash::verifyWithSalt($password, $hashedData['hash'], $hashedData['salt'])) {
echo "Password is verified!";
} else {
echo "Password verification failed.";
}
use Tal7aouy\HashLib\HashLib;
$passwordValidator = HashLib::getInstance();
$passwordValidator->setUseLowerCase(true);
$passwordValidator->setUseUpperCase(true);
$passwordValidator->setUseNumbers(true);
$passwordValidator->setUseSymbols(true);
$password = "Complex@Passw0rd";
$result = $passwordValidator->meetsRequirements($password);
if ($result === true) {
echo "Password meets all requirements.";
} else {
echo "Password requirements not met: " . $result;
}
For a comprehensive list of methods and their descriptions, please refer to the full documentation.
Below is a quick overview of some of the key methods available in the HashLib
library:
Set the minimum required length for generated passwords.
Specify whether lowercase letters are required in generated passwords.
Specify whether uppercase letters are required in generated passwords.
Specify whether numbers are required in generated passwords.
Specify whether symbols are required in generated passwords.
Set multiple password requirements at once.
Generate a random salt using base64 encoding.
Check if a password is already hashed.
Hash a password using the specified algorithm and options.
Verify if a password matches a given hash.
Hash a password with a randomly generated salt.
Verify if a password, when combined with a salt, matches a given hash.
Set the password to be used for hashing and validation.
Get the currently set password.
Check if a given password meets the specified requirements.
For detailed usage instructions and examples, please see the Usage section above.
Version: 1.0.0
License: MIT
For any questions, issues, or feedback, please reach out to the library's author, Mhammed Talhaouy.