yohns/hash

A simple hashing technique for forms

0.5.0 2024-11-22 19:48 UTC

This package is auto-updated.

Last update: 2025-02-22 20:32:04 UTC


README

A secure and efficient PHP library for generating, validating, and managing tokens.

Installation

Install the package via Composer:

composer require yohns/hash

Usage

1. Generating a Token

Use the generateToken method to create a secure token.

use Yohns\Security\Finding\Hash;

$token = Hash::generateToken('form-id'); // This value will be used again to validate the token
// add token to form
echo '<input type="hidden" name="YohnsPatch" value="'.$token.'">';

2. Validating a Token

Verify the validity of a token with the validateToken method.

use Yohns\Security\Finding\Hash;

$isValid = Hash::validateToken('form-id', $_POST['YohnsPatch']);
if ($isValid) {
	echo 'Token is valid!';
} else {
	echo 'Token is invalid or expired.';
}

3. Garbage Collection

Remove expired tokens to maintain optimal performance.

use Yohns\Security\Finding\Hash;

Hash::garbageCollect();
echo 'Expired tokens removed.';

Running Tests

Ensure everything works as expected by running the test suite:

composer test

Requirements

License

This library is licensed under MIT License.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.