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. ozanhazer/php-htpasswd

ActiveLibrary

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.0.0(4y ago)417.8k↑73.9%12MITPHPPHP ^7.2|^8.0

Since Feb 2Pushed 4y 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 today

READMEChangelog (1)Dependencies (1)Versions (2)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)

PHP Htpasswd writer for Apache. You can add or delete users, or update their passwords.

Features
--------

[](#features)

- Supports `crypt`, `md5` and `sha1` algorithms
- Locks the htpasswd file to prevent conflicts while writing.
- Throws an error on invalid usernames.
- Unit tested.
- Whole htpasswd file is read into the memory so be careful if you have lots of users (In fact you should consider a different kind of authentication mechanism if you have that many users)

Usage
-----

[](#usage)

Install: `composer require ozanhazer/php-htpasswd`

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

Apache htpasswd can be encrypted in three ways: crypt (unix only), a modified version of md5 and sha1. You can define the encryption method when you're setting the password:

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

(Yes, you may use different algorithms per user in the same passwd file...)

See [the Apache documentation](https://httpd.apache.org/docs/2.2/misc/password_encryptions.html) for encryption details.

Tips
----

[](#tips)

- Do not prefer `ENCTYPE_CRYPT` on Windows servers since it's not available on Windows by default.
- `ENCTYPE_CRYPT` passwords are limited to 8 characters and extra characters will be ignored so the library will trigger a notice if long passwords are provided.

###  Health Score

34

—

LowBetter than 78% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

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

1511d 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 (21 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

[pestphp/pest-plugin-stressless

Stressless plugin for Pest

67723.5k15](/packages/pestphp-pest-plugin-stressless)

PHPackages © 2026

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