PHPackages                             prokki/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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. prokki/htpasswd

ActiveSymfony-bundle[Authentication &amp; Authorization](/categories/authentication)

prokki/htpasswd
===============

This symfony user provider reads user from the htpasswd file.

1.0(3y ago)08.1k1MITPHPPHP &gt;=8.0.1

Since Aug 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/prokki/htpasswd)[ Packagist](https://packagist.org/packages/prokki/htpasswd)[ Docs](https://github.com/prokki/htpasswd)[ RSS](/packages/prokki-htpasswd/feed)WikiDiscussions main Synced 4d ago

READMEChangelogDependencies (7)Versions (5)Used By (0)

Htpasswd
========

[](#htpasswd)

[![Latest Stable Version](https://camo.githubusercontent.com/5beebbb6d3c17720e4d6729617e35848af4572181c927beb880aa8725f17f64a/68747470733a2f2f706f7365722e707567782e6f72672f70726f6b6b692f68747061737377642f76657273696f6e)](https://packagist.org/packages/prokki/htpasswd)[![Total Downloads](https://camo.githubusercontent.com/93b508f347e06e30fdbc20ba40af7caf0c7c938ffeab5377144bd28a5f376a7c/68747470733a2f2f706f7365722e707567782e6f72672f70726f6b6b692f68747061737377642f646f776e6c6f616473)](https://packagist.org/packages/prokki/htpasswd)[![License](https://camo.githubusercontent.com/91028d0e08e14f26bba09851d403bab92620ff159b63bbc68cfca3a958b1707d/68747470733a2f2f706f7365722e707567782e6f72672f70726f6b6b692f68747061737377642f6c6963656e7365)](https://packagist.org/packages/prokki/htpasswd)[![PHP v8.0.2](https://camo.githubusercontent.com/32fa60afba3b307c65e30e7c2039b24c5368d28701b9b76bf8cf6dc0e4e48021/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d2545322538392541353825324530253245322d3030343461612e737667)](https://www.php.net/manual/en/migration72.new-features.php)[![Symfony 6](https://camo.githubusercontent.com/4e58e4e2f3bcdd2f508d7afe74b6a83da0634dfb7845e37a9e76e86a6cba0e31/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d254532253839254135362d3030343461612e737667)](https://symfony.com/)

This symfony user provider reads user from the [htpasswd file](http://httpd.apache.org/docs/current/misc/password_encryptions.html).

To use the a htpasswd file you need to execute following three steps:

1. Run composer to install the bundle,
2. configure your security configuration and
3. create a htpasswd password storage file.

All available password formats [of the basic authentication](https://httpd.apache.org/docs/2.4/howto/auth.html) are supported: `apr1-md5`, `bcrypt`, `crypt`, `sha1` and plain text - see [http://httpd.apache.org/docs/current/misc/password\_encryptions.html](http://httpd.apache.org/docs/current/misc/password_encryptions.html).

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

[](#table-of-contents)

- [Requirements](#requirements)
- [Integration &amp; Basic Usage](#integration--basic-usage)
    - [Installation](#installation)
    - [Symfony Configuration](#symfony-configuration)
    - [Add Htpasswd File](#add-htpasswd-file)
- [Advanced Usage &amp; Configuration](#advanced-usage--configuration)
    - [Change Location of Your Htpasswd File](#change-location-of-your-htpasswd-file)
    - [Change Default User Roles](#change-default-user-roles)
    - [User Roles Inside Htpasswd File](#user-roles-inside-htpasswd-file)
- [Credits](#credits)

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

[](#requirements)

The usage of [**PHP ≥ v8.0.2**](https://www.php.net/manual/en/migration80.php)and [**Symfony ≥ 6**](https://symfony.com/doc/4.0/setup.html) is recommend.

Integration &amp; Basic Usage
-----------------------------

[](#integration--basic-usage)

### Installation

[](#installation)

Please install via [composer](https://getcomposer.org/).

```
composer require prokki/htpasswd
```

The bundle will be automatically added to your `bundles.yaml` configuration.

### Symfony v4, Symfony v5

[](#symfony-v4-symfony-v5)

[**PHP v7.2**](https://www.php.net/manual/en/migration72.new-features.php)and [**Symfony 4**](https://symfony.com/doc/4.0/setup.html) is obligatory.

To use an older version of Symfony/PHP please use version `0.*`

```
composer require prokki/htpasswd "~0.0"
```

### Symfony Configuration

[](#symfony-configuration)

To enable the functionality you have to change your security configuration manually.

1. Enable the provider [HtpasswdUserProvider](src/Security/HtpasswdUserProvider.php)and the encoder [HtpasswdEncoder](src/Security/HtpasswdEncoder.php)in your security configuraton, i.e. in your `%kernel.project_dir%/config/security.yaml` file.
2. To enable http basic authentication add the `http_basic` authentication method to the firewall configuration.
3. Additionally be sure to enable **access\_control** for at least one path.

**`security.yaml`**:

```
security:

  # 1.a) add the HtpasswdUserProvider as a new provider (the name does not matter)
  providers:
    bz_map_cycle_provider:
      id: Htpasswd\Security\HtpasswdUserProvider

  # 1.b) and add the HtpasswdEncoder as a new encoder (the name does not matter)
  encoders:
    Symfony\Component\Security\Core\User\User:
      id: Htpasswd\Security\HtpasswdEncoder

  # 2. enable basic authentication
  firewalls:
    main:
      http_basic: ~

  # 3. be sure to add one path
  access_control:
    - { path: ^/, roles: ROLE_USER }
```

Feel free to use the full flexibility of the Symfoniy security layer which means i.e. you can

- chain firewalls,
- add other providers and encoders,
- restrict basic authentication to certain paths only
- etc.

### Add Htpasswd File

[](#add-htpasswd-file)

Create your custom htpasswd file using the [htpasswd](https://httpd.apache.org/docs/2.4/programs/htpasswd.html) command in the project directory of your project.

Hint: Usually the command is installed automatically if you run an [apache](https://httpd.apache.org/) web server, i.e. if you use [xampp](https://www.apachefriends.org/) or your package management system. On linux systems the command is mostly provided by the package `apache2-utils`.

Create a htpasswd file in your project directory. Call the following command and type in your password:

```
htpasswd -cB .htpasswd admin
```

A new file was created in your project:

```
%kernel.project_dir%/
  - config/
    - packages/
      - security.yaml
