loopire / password-helper
Custom password hasing and comparing password using custom secret key
This package is not auto-updated.
Last update: 2025-04-29 15:38:44 UTC
README
A lightweight PHP package for secure password hashing using SHA-256 with multiple iterations and a custom secret key. Ideal for projects that require a simple, consistent, and dependency-free way to hash and verify passwords.
๐ฆ Installation
Clone or download the repository and include the class in your PHP project:
require_once 'PasswordHelper.php';
๐ Features
- ๐ Configurable iteration count for added security (default: 500)
- ๐ SHA-256 based hashing with secret key
- โ๏ธ Secure password comparison
- ๐งฑ Dependency-free
๐งช Usage
โ Hash a Password
require_once 'PasswordHelper.php'; $hashedPassword = PasswordHelper::hashPassword('your_password', 'your_secret_key'); echo "Hashed Password: " . $hashedPassword;
๐ Compare Passwords
require_once 'PasswordHelper.php'; $plainPassword = 'your_password'; $hashedPassword = PasswordHelper::hashPassword($plainPassword, 'your_secret_key'); $isValid = PasswordHelper::comparePassword($plainPassword, $hashedPassword, 'your_secret_key'); if ($isValid) { echo "Password is valid!"; } else { echo "Invalid password."; }
๐ง Behind the Scenes
The PasswordHelper
class works by combining your password and secret key, then running it through the SHA-256 hashing algorithm 500 times by default:
$hash = $secretKey . $password . $secretKey; for ($i = 0; $i < 500; $i++) { $hash = hash('sha256', $hash); }
This helps to strengthen the hash and reduce the risk of brute-force attacks.
โ ๏ธ Security Notice
While this custom method adds basic security, it is highly recommended to use PHP's built-in
password_hash()
andpassword_verify()
functions for production environments. These are battle-tested and offer protections against common security vulnerabilities including timing attacks.
๐ License
MIT License
๐ Contributing
Pull requests are welcome! If you have suggestions or improvements, feel free to contribute.
๐จโ๐ป Author
Developed by [Arsalan Ahmed].
For any questions or support, reach out via GitHub Issues.
https://github.com/Arsalan-Ahmed-Solangi