loopire/password-helper

Custom password hasing and comparing password using custom secret key

v1.0.0 2025-04-14 18:14 UTC

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() and password_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