PHPackages                             codemonauts/craft-basicauth - 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. codemonauts/craft-basicauth

ActiveCraft-plugin[Authentication &amp; Authorization](/categories/authentication)

codemonauts/craft-basicauth
===========================

Craft CMS plugin for HTTP Basic Authentication within templates.

2.0.1(3mo ago)929.2k↓54.9%3[1 issues](https://github.com/codemonauts/craft-basicauth/issues)[1 PRs](https://github.com/codemonauts/craft-basicauth/pulls)MITPHP

Since Feb 2Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/codemonauts/craft-basicauth)[ Packagist](https://packagist.org/packages/codemonauts/craft-basicauth)[ RSS](/packages/codemonauts-craft-basicauth/feed)WikiDiscussions development Synced 3d ago

READMEChangelog (3)Dependencies (4)Versions (8)Used By (0)

HTTP Basic Authentication for Craft CMS
=======================================

[](#http-basic-authentication-for-craft-cms)

[![Icon](resources/basicauth.png)](resources/basicauth.png)

A plugin for Craft CMS that provides HTTP Basic Authentication (BasicAuth) within templates.

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

[](#requirements)

- Craft CMS &gt;= 4.0.0

Installation
------------

[](#installation)

Open your terminal and go to your Craft project:

```
cd /path/to/project
composer require codemonauts/craft-basicauth
./craft install/plugin basicauth
```

### Apache

[](#apache)

If you are using Apache to host your CraftCMS, you have to tell Apache to pass the `Authorization` header (which contains the basic auth data) to PHP (See the [Documentation](https://httpd.apache.org/docs/trunk/mod/core.html#cgipassauth)). Otherwise, Craft will never see any credentials and will continue to show you the dialog to enter your username and password. This can either be set directly in the Apache config file or in your `.htaccess`:

```
CGIPassAuth on

```

Settings
--------

[](#settings)

On the settings page in the control panel you can add credentials to use for authentication.

[![Screenshot](resources/settings.png)](resources/settings.png)

You can add a list of IP addresses and subnets (v4 and v6) that have access without any credentials. Use the [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation) for subnets.

These settings support the project config if enabled.

{% basicauth %} Tag
-------------------

[](#-basicauth--tag)

In your templates you can require BasicAuth:

```
{% basicauth require valid env "stage" %}
```

### Parameters

[](#parameters)

The `{% basicauth %}` tag supports the following parameters:`

#### `require`

[](#require)

This specifies the type of check to be made. You can check against a single `user`, a `group` of user, any `valid` user and also accept `any` provided credentials.

```
{# require a single user #}
{% basicauth require user "bob" %}

{# require the user to be a member of a group #}
{% basicauth require group "admins" %}

{# accept any valid credentials #}
{% basicauth require valid %}

{# accept any credentials without checking them #}
{% basicauth require any %}
```

This parameter is **required**.

#### `site`

[](#site)

This specifies the site handle for which the authentication should be made. The Authentication is only enforced when the current site handle is the same as specified.

```
{# require the user "bob" if the current site handle is "acme" #}
{% basicauth require user "bob" site "acme" %}
```

#### `env`

[](#env)

This specifies the environment for which the authentication should be made. The Authentication is only enforced when the current environment is the same as specified.

```
{# require the user to be a member of the group "customer" if the current environment is "stage" #}
{% basicauth require group "customer" env "stage" %}
```

#### `if`

[](#if)

Only activates the BasicAuth if a certain condition is met.

```
{% basicauth require valid if craft.app.request.isMobileBrowser() %}
```

Globals
-------

[](#globals)

This plugin provides two global variables with the credentials of the user:

```
Hello {{ basicAuthUsername }}!
Your password is: {{ basicAuthPassword }}
```

Why should I use this plugin and not the webserver module?
----------------------------------------------------------

[](#why-should-i-use-this-plugin-and-not-the-webserver-module)

May you ask yourself why you should use this plugin and not the Basic Authentication provided by the webserver? Here are some aspects:

1. You have full control of the Basic Authentication without your DevOps friends.
2. You can add the `{% basicauth %}` wherever you need it: In your central layout for all pages or only in one special template with some fancy conditions.
3. You can use conditions from Craft. For example: `{% basicauth require valid if not currentUser %}`

With ❤ by [codemonauts](https://codemonauts.com)

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance75

Regular maintenance activity

Popularity34

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 92.3% 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 ~556 days

Total

5

Last Release

118d ago

Major Versions

1.1.0 → 2.0.02022-05-04

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/539161?v=4)[codemonauts](/maintainers/codemonauts)[@codemonauts](https://github.com/codemonauts)

---

Top Contributors

[![kringkaste](https://avatars.githubusercontent.com/u/964698?v=4)](https://github.com/kringkaste "kringkaste (12 commits)")[![qrazi](https://avatars.githubusercontent.com/u/7550540?v=4)](https://github.com/qrazi "qrazi (1 commits)")

---

Tags

cmsCraftcraftcmscraft-plugin

### Embed Badge

![Health badge](/badges/codemonauts-craft-basicauth/health.svg)

```
[![Health](https://phpackages.com/badges/codemonauts-craft-basicauth/health.svg)](https://phpackages.com/packages/codemonauts-craft-basicauth)
```

###  Alternatives

[verbb/formie

The most user-friendly forms plugin for Craft.

102393.6k70](/packages/verbb-formie)[verbb/vizy

A flexible visual editor field for Craft.

4250.4k](/packages/verbb-vizy)[verbb/hyper

A user-friendly links field for Craft.

24147.8k12](/packages/verbb-hyper)[verbb/knock-knock

Password protect your public facing Craft website with a single password.

17124.9k9](/packages/verbb-knock-knock)[verbb/events

A full-featured plugin for event management and ticketing.

2311.9k](/packages/verbb-events)[verbb/autologin

Automatically login based on whitelisted IP, basic auth username or URL keys.

162.3k](/packages/verbb-autologin)

PHPackages © 2026

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