PHPackages                             axy/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. axy/htpasswd

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

axy/htpasswd
============

Working with htpasswd file

2.0.0(3y ago)026.1k↓40.3%23MITPHPPHP &gt;=8.1

Since Nov 29Pushed 3y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (7)Used By (3)

axy\\htpasswd
=============

[](#axyhtpasswd)

Working with htpasswd file (PHP).

[![Latest Stable Version](https://camo.githubusercontent.com/445ea36fc9facddae7cf344cd678a5fd658533c5c16cc44cc0f08b54bb332031/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6178792f68747061737377642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/axy/htpasswd)[![Minimum PHP Version](https://camo.githubusercontent.com/2d18ce514c7016022dad012ac9e39a8b6f47cc411b2daff6627cbf208f8cea63/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Tests](https://github.com/axypro/htpasswd/actions/workflows/test.yml/badge.svg)](https://github.com/axypro/htpasswd/actions/workflows/test.yml)[![Coverage Status](https://camo.githubusercontent.com/0677fa141480d4e145ed1c105b6fb0819d9cd819e8fed4175937c3feccffd35c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f61787970726f2f68747061737377642f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/axypro/htpasswd?branch=master)[![License](https://camo.githubusercontent.com/ff3be24eea7be2f31ee71227468b71235546935970757e82ffa99d3aeff727fc/68747470733a2f2f706f7365722e707567782e6f72672f6178792f68747061737377642f6c6963656e7365)](LICENSE)

### Documentation

[](#documentation)

The library provides program API for manipulation with htpasswd file (for console utility see [axypro/htpasswd-cli](https://github.com/axypro/htpasswd-cli)).

```
use axy\htpasswd\PasswordFile;

$file = new PasswordFile('/path/to/.htpasswd');
$file->setPassword('nick', 'password');
$file->setPassword('john', '123456');
$file->save();
```

Currently supported the following algorithms (constants of `PasswordFile::*`):

- `ALG_MD5`: Apache APR1-MD5 algorithm (by default)
- `ALG_BCrypt`: Blowfish
- `ALG_SHA1`: SHA-1
- `ALG_CRYPT`: crypt (unix)
- `ALG_PLAIN`: Plain text (not supported of servers on some platforms).

##### `__construct([string $filename])`

[](#__constructstring-filename)

The constructor takes the name of a htpasswd file.

Or `NULL`: analogue of the option `-n` of the console utility:

```
$file = new PasswordFile();
$file->setPassword('nick', 'password');
$file->getContent(); // out of the "file" content

$file->save(); // Exception FileNotSpecified
```

##### `setPassword(string $user, string $password [, string $algorithm, [array $options]): bool`

[](#setpasswordstring-user-string-password--string-algorithm-array-options-bool)

Sets the password `$password` for a user `$user`. For hashing uses `$algorithm` (by default Apache MD5).

`$options` is an array of options for hashing. Only `cost` for BCrypt supported (integer in the range 4 to 31)

Returns `TRUE` if a new user has been created. And `FALSE` if has been changed the password of an existing user.

##### `remove(string $user): bool`

[](#removestring-user-bool)

Removes a user from the file. Returns `TRUE` is the user has been removed. And `FALSE` if the user was not found.

##### `verify(string $user, string $password): bool`

[](#verifystring-user-string-password-bool)

Returns `TRUE` if a `$user` exists and has `$password` as the password.

##### `isUserExist(string $user): bool`

[](#isuserexiststring-user-bool)

Returns `TRUE` is a user exists in the file.

```
if (!$file->isUserExist('john')) {
    echo 'John? I do not known you.';
    exit();
}
if (!$file->verify('john', 'password')) {
    echo 'You are not John! You are an impostor!';
    exit();
}
echo 'Hello, John';
```

##### `getContent(void): string`

[](#getcontentvoid-string)

Returns the file content (without saving).

##### `save(void): void`

[](#savevoid-void)

Saves the content to the file (if it is specified).

In contrast, from the utility `htpasswd` (see the option `-c`) the existing file always changing (not overwritten). Nonexistent file is created.

##### `setFileName(string $filename): void`

[](#setfilenamestring-filename-void)

Sets a new filename. The content of the old file will be loaded and saved to the new (after `save()`).

##### `getFileName(void): string`

[](#getfilenamevoid-string)

Returns the current specified file name.

### Exceptions

[](#exceptions)

In the `axy\htpasswd\errors` namespace.

- `InvalidFileFormat`: a password file has invalid format.
- `FileNotSpecified`: throws from `save()` if the file is not specified in the constructor.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity76

Established project with proven stability

 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

Every ~533 days

Recently: every ~665 days

Total

6

Last Release

1157d ago

Major Versions

0.1.2 → 1.0.02015-12-05

1.0.1 → 2.0.02023-03-18

PHP version history (2 changes)0.1.0PHP &gt;=5.4.0

2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/e5b3a2db8d5614167d4510019e3373dbba63c6aade58d38d23f3e7d2e63c3c4a?d=identicon)[axy](/maintainers/axy)

---

Top Contributors

[![vasa-c](https://avatars.githubusercontent.com/u/557081?v=4)](https://github.com/vasa-c "vasa-c (44 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[axy/sourcemap

Work with JavaScript/CSS Source Map

24734.1k5](/packages/axy-sourcemap)

PHPackages © 2026

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