PHPackages                             lithemod/hash - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. lithemod/hash

ActiveLibrary[Security](/categories/security)

lithemod/hash
=============

An effective module for hashing passwords using Bcrypt.

v1.0.0(1y ago)116MITPHPPHP ^8.0

Since Oct 2Pushed 1y agoCompare

[ Source](https://github.com/lithemod/hash)[ Packagist](https://packagist.org/packages/lithemod/hash)[ RSS](/packages/lithemod-hash/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Lithe Hash
==========

[](#lithe-hash)

A robust module for securely hashing passwords using Bcrypt. This module simplifies the process of creating, verifying, and managing password hashes, ensuring security best practices are followed.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Importing the Class](#importing-the-class)
    - [Creating a Hash](#creating-a-hash)
    - [Verifying a Hash](#verifying-a-hash)
    - [Checking if a Hash Needs Rehashing](#checking-if-a-hash-needs-rehashing)
- [Understanding Bcrypt](#understanding-bcrypt)
- [Handling Exceptions](#handling-exceptions)
- [Testing](#testing)
- [License](#license)

Installation
------------

[](#installation)

To install the `lithemod/hash` package, you can use Composer. Run the following command in your terminal:

```
composer require lithemod/hash
```

This will add the package to your project's dependencies, allowing you to use the `Hash` class in your application.

Usage
-----

[](#usage)

### Importing the Class

[](#importing-the-class)

Before using the `Hash` class, you must import it in your PHP file:

```
use Lithe\Support\Security\Hash;
```

### Creating a Hash

[](#creating-a-hash)

To create a hash from a password, use the `make` method. The method accepts a password and an optional array of options:

```
$hash = Hash::make('your_password', ['cost' => 10]);
```

- **Parameters**:
    - `string $value`: The password to be hashed.
    - `array $options`: Optional parameters (e.g., cost) to adjust the hashing algorithm.
- **Returns**: A hashed string that can be stored in a database.

**Example**:

```
$password = 'my_secure_password';
$hash = Hash::make($password, ['cost' => 12]);
echo "Hashed Password: " . $hash;
```

### Verifying a Hash

[](#verifying-a-hash)

To check if a given password matches the hash, use the `check` method:

```
$isValid = Hash::check('your_password', $hash);
if ($isValid) {
    echo 'Password is valid!';
} else {
    echo 'Invalid password.';
}
```

- **Parameters**:
    - `string $value`: The password to verify.
    - `string $hash`: The hashed password to compare against.
- **Returns**: `true` if the password matches the hash; `false` otherwise.

**Example**:

```
if (Hash::check('my_secure_password', $hash)) {
    echo 'Password is correct!';
} else {
    echo 'Password is incorrect!';
}
```

### Checking if a Hash Needs Rehashing

[](#checking-if-a-hash-needs-rehashing)

You can determine if a hash needs to be rehashed (for example, if you change the cost factor) using the `needsRehash` method:

```
$needsRehash = Hash::needsRehash($hash, ['cost' => 14]);
if ($needsRehash) {
    // Rehash with a new cost
    $hash = Hash::make('your_password', ['cost' => 14]);
}
```

- **Parameters**:
    - `string $hash`: The hashed password to evaluate.
    - `array $options`: Optional parameters to specify the cost.
- **Returns**: `true` if the hash needs to be rehashed; `false` otherwise.

**Example**:

```
if (Hash::needsRehash($hash, ['cost' => 15])) {
    $hash = Hash::make('my_secure_password', ['cost' => 15]);
    echo "Rehashed Password: " . $hash;
}
```

Understanding Bcrypt
--------------------

[](#understanding-bcrypt)

Bcrypt is a widely-used password hashing function designed to be slow and computationally intensive, making it resistant to brute-force attacks. By using a configurable cost factor, Bcrypt allows you to increase the difficulty of hashing as hardware becomes faster.

- **Cost Factor**: The cost factor determines the computational complexity of hashing a password. It represents the number of iterations of the hashing algorithm. A higher cost means more security but also increases processing time. The recommended range is between 10 and 12 for most applications.

Handling Exceptions
-------------------

[](#handling-exceptions)

The `make` method throws an `InvalidArgumentException` if the cost is set outside the valid range (4 to 31). You should handle this in your code to ensure robustness:

```
try {
    $hash = Hash::make('your_password', ['cost' => 3]); // Invalid cost
} catch (\InvalidArgumentException $e) {
    echo "Error: " . $e->getMessage();
}
```

Testing
-------

[](#testing)

To ensure that your installation of the `lithemod/hash` module works correctly, you can run the included unit tests. If you have PHPUnit installed, execute the following command in your project directory:

```
./vendor/bin/phpunit
```

This will run the tests defined in the `Tests` namespace and validate the functionality of the `Hash` class.

License
-------

[](#license)

This package is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

594d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/56173de3a7bf7099dd8168efd730d3c2fb5df5174a123fdc37cee8c3589e2345?d=identicon)[williamhumbwavali](/maintainers/williamhumbwavali)

---

Top Contributors

[![williamhumbwavali](https://avatars.githubusercontent.com/u/127023095?v=4)](https://github.com/williamhumbwavali "williamhumbwavali (1 commits)")

---

Tags

hashingmodulephp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lithemod-hash/health.svg)

```
[![Health](https://phpackages.com/badges/lithemod-hash/health.svg)](https://phpackages.com/packages/lithemod-hash)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41478.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

87117.5M63](/packages/bjeavons-zxcvbn-php)[illuminate/encryption

The Illuminate Encryption package.

9229.7M280](/packages/illuminate-encryption)[paragonie/hidden-string

Encapsulate strings in an object to hide them from stack traces

7410.6M39](/packages/paragonie-hidden-string)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
