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

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

gloomers/htpasswd
=================

This symfony user provider reads user from the htpasswd file.

013PHP

Since Jan 1Pushed 5y agoCompare

[ Source](https://github.com/gloomy/htpasswd)[ Packagist](https://packagist.org/packages/gloomers/htpasswd)[ RSS](/packages/gloomers-htpasswd/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)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 v7.2](https://camo.githubusercontent.com/5b829d79828a63f4ce1838b7bfc13cfcea10e5089c19339e63849114df245aee/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d25453225383925413537253245322d3030343461612e737667)](https://www.php.net/manual/en/migration72.new-features.php)[![Symfony 4](https://camo.githubusercontent.com/8ca9d53e8b1176c10660a13b26a0457e9c8b6ddd1e1358829b271670cbf07eb5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d254532253839254135342d3030343461612e737667)](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 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.

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

[](#integration--basic-usage)

### Installation

[](#installation)

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

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

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

### 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
