PHPackages                             ozanhazer/php-htpasswd - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ozanhazer/php-htpasswd

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ozanhazer/php-htpasswd
======================

A lightweight - single class - library to read and write htpasswd. You can add or delete users or you can update their passwords...

v1.1.0(3w ago)418.0k↑29.5%12MITPHPPHP ^7.2|^8.0CI passing

Since Feb 2Pushed 3w ago4 watchersCompare

[ Source](https://github.com/ozanhazer/PHP-Htpasswd)[ Packagist](https://packagist.org/packages/ozanhazer/php-htpasswd)[ Docs](https://github.com/ozanhazer/PHP-Htpasswd)[ RSS](/packages/ozanhazer-php-htpasswd/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

PHP-Htpasswd
============

[](#php-htpasswd)

[![Unit Tests](https://github.com/ozanhazer/PHP-Htpasswd/actions/workflows/php.yml/badge.svg)](https://github.com/ozanhazer/PHP-Htpasswd/actions/workflows/php.yml/badge.svg)

A lightweight PHP library for reading and writing Apache htpasswd files. You can add or delete users or update their passwords.

Requirements
------------

[](#requirements)

- PHP 7.2 or higher (tested on 8.2–8.5)

Features
--------

[](#features)

- Supports `crypt`, APR-MD5, SHA-1 and bcrypt algorithms
- Locks the htpasswd file to prevent conflicts while writing
- Throws exceptions on invalid usernames
- Unit tested

> **Note:** The entire htpasswd file is loaded into memory. If you have a very large number of users, consider a different authentication mechanism.

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

[](#installation)

```
composer require ozanhazer/php-htpasswd
```

Usage
-----

[](#usage)

The `Htpasswd` class has no namespace, so it works in both non-namespaced and namespaced projects:

```
use Htpasswd;

$htpasswd = new Htpasswd('/path/to/.htpasswd');
$htpasswd->addUser('ozan', '123456');
$htpasswd->updateUser('ozan', '654321');
$htpasswd->deleteUser('ozan');
```

### Encryption algorithms

[](#encryption-algorithms)

Apache htpasswd supports three password formats. You can specify the algorithm when adding or updating a user:

```
$htpasswd->addUser('ozan', '123456', Htpasswd::ENCTYPE_APR_MD5);
$htpasswd->addUser('ozan', '123456', Htpasswd::ENCTYPE_SHA1);
$htpasswd->addUser('ozan', '123456', Htpasswd::ENCTYPE_BCRYPT);
$htpasswd->addUser('ozan', '123456', Htpasswd::ENCTYPE_CRYPT);  // default
```

Different users in the same htpasswd file can use different algorithms.

See the [Apache documentation](https://httpd.apache.org/docs/2.4/misc/password_encryptions.html) for details on each format.

Tips
----

[](#tips)

- Avoid `ENCTYPE_CRYPT` on Windows — it is not available by default.
- `ENCTYPE_CRYPT` passwords are limited to 8 characters; extra characters are silently ignored. The library will trigger a notice if a longer password is provided.
- SHA-1 (`ENCTYPE_SHA1`) is considered weak. APR-MD5 is the most broadly compatible option; bcrypt (`ENCTYPE_BCRYPT`) is the strongest and is recommended for Apache 2.4+.

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance95

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.1% 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

Every ~789 days

Total

3

Last Release

25d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5d4cb7f879c70b06456629132578cb92e0033c1a741af2ee285a4ee284bba610?d=identicon)[ozanhazer](/maintainers/ozanhazer)

---

Top Contributors

[![ozanhazer](https://avatars.githubusercontent.com/u/1287658?v=4)](https://github.com/ozanhazer "ozanhazer (33 commits)")[![LoginovIlya](https://avatars.githubusercontent.com/u/224177579?v=4)](https://github.com/LoginovIlya "LoginovIlya (1 commits)")

---

Tags

phphtpasswd

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ozanhazer-php-htpasswd/health.svg)

```
[![Health](https://phpackages.com/badges/ozanhazer-php-htpasswd/health.svg)](https://phpackages.com/packages/ozanhazer-php-htpasswd)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21422.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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