Download the PHP package ozanhazer/php-htpasswd without Composer
On this page you can find all versions of the php package ozanhazer/php-htpasswd. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ozanhazer/php-htpasswd
More information about ozanhazer/php-htpasswd
Files in ozanhazer/php-htpasswd
Package php-htpasswd
Short Description A lightweight - single class - library to read and write htpasswd. You can add or delete users or you can update their passwords...
License MIT
Homepage https://github.com/ozanhazer/PHP-Htpasswd
Informations about the package php-htpasswd
PHP-Htpasswd
A lightweight PHP library for reading and writing Apache htpasswd files. You can add or delete users or update their passwords.
Requirements
- PHP 7.2 or higher (tested on 8.2–8.5)
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
Usage
The Htpasswd class has no namespace, so it works in both non-namespaced and namespaced projects:
Encryption algorithms
Apache htpasswd supports three password formats. You can specify the algorithm when adding or updating a user:
Different users in the same htpasswd file can use different algorithms.
See the Apache documentation for details on each format.
Tips
- Avoid
ENCTYPE_CRYPTon Windows — it is not available by default. ENCTYPE_CRYPTpasswords 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+.