PHPackages                             olssonm/l5-very-basic-auth - 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. olssonm/l5-very-basic-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

olssonm/l5-very-basic-auth
==========================

Laravel stateless HTTP basic auth without the need for a database

v7.4(2mo ago)1662.5M↑18.1%281MITPHPPHP ^8.2CI passing

Since Aug 9Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/olssonm/l5-very-basic-auth)[ Packagist](https://packagist.org/packages/olssonm/l5-very-basic-auth)[ Docs](https://github.com/olssonm/l5-very-basic-auth)[ GitHub Sponsors](https://github.com/olssonm)[ RSS](/packages/olssonm-l5-very-basic-auth/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (49)Used By (1)

Laravel Very Basic Auth
=======================

[](#laravel-very-basic-auth)

[![Latest Version on Packagist](https://camo.githubusercontent.com/636a90e5db944e7a2ccc48e695fb342910c5080530a13506b86f4da3153ca9cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6c73736f6e6d2f6c352d766572792d62617369632d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/olssonm/l5-very-basic-auth)[![Total downloads](https://camo.githubusercontent.com/5985f5bb4fc9642060e757cd50dffddbf0f3159a5dc3640f98c2930e98d545aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6c73736f6e6d2f6c352d766572792d62617369632d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/olssonm/l5-very-basic-auth)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/e3acb5f4c779974217836cf83593e3a711b3a0f4375e6045a01afb4028c7de5e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f6c73736f6e6d2f6c352d766572792d62617369632d617574682f746573742e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/olssonm/l5-very-basic-auth/actions?query=workflow%3A%22Run+tests%22)

[![very-basic-auth](https://user-images.githubusercontent.com/907114/40575964-331559ce-60ef-11e8-8366-aba700fc5567.png)](https://user-images.githubusercontent.com/907114/40575964-331559ce-60ef-11e8-8366-aba700fc5567.png)

**Documentation available in:**

🇬🇧 [English](README.md)
🇯🇵 [日本語](README.jp.md)

This package allows you to add a HTTP Basic Auth filter on your routes, without the need to use a database – which the Laravel default `auth.basic`-middleware relies on.

[![Screenshot](https://user-images.githubusercontent.com/907114/29876493-3907afd8-8d9d-11e7-8068-f461855c493b.png)](https://user-images.githubusercontent.com/907114/29876493-3907afd8-8d9d-11e7-8068-f461855c493b.png)

Perfect when you want to give your clients access to your development site before you have yet to set up your database and/or models. Or perhaps your site doesn't even use a database and you still wish to keep it protected.

On failed authentication the user will get a "401 Unauthorized" response.

#### A thing to note

[](#a-thing-to-note)

While HTTP Basic Auth does give you a protection layer against unwanted visitors, it is still not strictly safe from brute-force attacks. If you are solely using this package for security, you should at least consider looking into Apache or Nginx rate-limiters to limit login attempts.

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

[](#installation)

Via Composer

```
$ composer require olssonm/l5-very-basic-auth
```

Since v4.\* (for Laravel 5.5) this package uses Package Auto-Discovery for loading the service provider. Once installed you should see the message

```
Discovered Package: olssonm/l5-very-basic-auth

```

If you would like to manually add the provider, turn off Auto-Discovery for the package in your composer.json-file:

```
"extra": {
    "laravel": {
        "dont-discover": [
            "olssonm/l5-very-basic-auth"
        ]
    }
},
```

And then add the provider in the providers array (`config/app.php`).

```
'providers' => [
    Olssonm\VeryBasicAuth\VeryBasicAuthServiceProvider::class
]
```

Configuration
-------------

[](#configuration)

Run the command `$ php artisan vendor:publish` and select `Provider: Olssonm\VeryBasicAuth\VeryBasicAuthServiceProvider` to publish the configuration. You could also type `$ php artisan vendor:publish --provider="Olssonm\VeryBasicAuth\VeryBasicAuthServiceProvider"` to directly publish the files.

The file `very_basic_auth.php` will then be copied to your `app/config`-folder – here you can set various options such as username and password.

#### Note

[](#note)

**There is no default password**. Upon installation you will need to set your own username and password. Please publish the packages configuration to have the ability to set these. **If left empty, basic auth will not be active**.

### Environments

[](#environments)

You may set the environments that the package should be applied for. You may simply use "`*`" to use in all environments (this is also the default).

```
'envs' => [
    '*'
],
```

Or

```
'envs' => [
    'production',
    'development',
    'local'
],
```

### Response handlers

[](#response-handlers)

When the authentication fails the response handler sends out an error response (see "Views and messages" for more about these options). By default the handler will be `\Olssonm\VeryBasicAuth\Handlers\DefaultResponseHandler` (see `response_handler` in `very_basic_auth.php`). You may however write your own response-logic if you so choose. The only requirement is that it implements the `\Olssonm\VeryBasicAuth\Handlers\ResponseHandler`-interface, and has an `__invoke`-method that accepts a request-object, like so:

```
use Illuminate\Http\Request;
use Olssonm\VeryBasicAuth\Handlers\ResponseHandler;

class CustomResponseHandler implements ResponseHandler
{
    public function __invoke(Request $request)
    {
        // Do some stuff
        return response('Custom response', 401);
    }
}
```

### Views and messages

[](#views-and-messages)

In the `very_basic_auth.php`-configuration you have the ability to set a custom view instead of a message.

```
// Message to display if the user "opts out"/clicks "cancel"
'error_message'     => 'You have to supply your credentials to access this resource.',

// If you prefer to use a view with your error message you can uncomment "error_view".
// This will supersede your default response message
// 'error_view'        => 'very_basic_auth::default'
```

If you uncomment `error_view`, the middleware will try to find your specified view. You supply this value as usual (without the `.blade.php`-extention).

Usage
-----

[](#usage)

The middleware uses the `auth.very_basic`-filter to protect routes. You can either use `Route::group()` to protect multiple routes, or chose just to protect them individually.

**Group**

```
Route::group(['middleware' => 'auth.very_basic'], function() {
    Route::get('/', ['as' => 'start', 'uses' => 'StartController@index']);
    Route::get('/page', ['as' => 'page', 'uses' => 'StartController@page']);
});
```

**Single**

```
Route::get('/', [
    'as' => 'start',
    'uses' => 'StartController@index',
    'middleware' => 'auth.very_basic'
]);
```

You may also set the credentials inline;

```
Route::get('/', [
    'as' => 'start',
    'uses' => 'StartController@index',
    'middleware' => 'auth.very_basic:username,password'
]);
```

*Note:* inline credentials always take president over the `very_basic_auth.php`-configuration file.

### Generating hash for password

[](#generating-hash-for-password)

If you want to generate a hash for your password, you can use the `artisan`-command:

```
php artisan very-basic-auth:generate-password
```

It will ask you for a password, and then automatically insert the hash into your `.env`-file

Testing
-------

[](#testing)

```
$ composer test
```

or

```
$ phpunit
```

Laravel always runs in the "testing" environment while running tests. Make sure that `testing` is set in the `envs`-array in `very_basic_auth.php`.

Thank you
---------

[](#thank-you)

A big thank you to the people who has contributed to this package, among others:

**[kazuhei](https://github.com/kazuhei)** – for providing the awesome Japanese translation
**[freekmurze](https://github.com/freekmurze)** – for additional information on package/vendor installations
**[faiare](https://github.com/faiare)** – for pointing out and implementing the `realm`-attribute ([RFC7235](https://tools.ietf.org/html/rfc7235#section-2.2))

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

© 2024 [Marcus Olsson](https://marcusolsson.me).

###  Health Score

70

—

ExcellentBetter than 100% of packages

Maintenance88

Actively maintained with recent releases

Popularity59

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 86.9% 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 ~117 days

Recently: every ~225 days

Total

34

Last Release

60d ago

Major Versions

v3.0 → v4.02017-08-30

v4.1 → v5.02018-02-09

v1.2.2 → v5.22018-06-07

v5.6 → v6.02019-09-05

v6.9 → v7.02023-10-02

PHP version history (12 changes)v1.0PHP &gt;=5.3.0

v3.0PHP &gt;=5.6.0

v4.0PHP &gt;=7.0

v5.0PHP 7.\*

v5.1PHP ^7.0

v1.2.2PHP ^5.6 || ^7.0

v6.0PHP ^7.1

v6.4PHP ^7.2

v6.5PHP ^7.2|^8.0

v6.8PHP ~7.4|^8.0

v7.1PHP ^8.0 || ^8.1 || ^8.2

v7.4PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/74a309aadadeae81baef2394d37375673d03f11133b28a831a30825361d1d68c?d=identicon)[olssonm](/maintainers/olssonm)

---

Top Contributors

[![olssonm](https://avatars.githubusercontent.com/u/907114?v=4)](https://github.com/olssonm "olssonm (126 commits)")[![faiare](https://avatars.githubusercontent.com/u/11206952?v=4)](https://github.com/faiare "faiare (3 commits)")[![kazuhei](https://avatars.githubusercontent.com/u/3251744?v=4)](https://github.com/kazuhei "kazuhei (2 commits)")[![RowdyElectron](https://avatars.githubusercontent.com/u/4397586?v=4)](https://github.com/RowdyElectron "RowdyElectron (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![msng](https://avatars.githubusercontent.com/u/29099?v=4)](https://github.com/msng "msng (1 commits)")[![rhynodesigns](https://avatars.githubusercontent.com/u/2198266?v=4)](https://github.com/rhynodesigns "rhynodesigns (1 commits)")[![sweptsquash](https://avatars.githubusercontent.com/u/9886472?v=4)](https://github.com/sweptsquash "sweptsquash (1 commits)")[![treyssatvincent](https://avatars.githubusercontent.com/u/18269685?v=4)](https://github.com/treyssatvincent "treyssatvincent (1 commits)")[![53ningen](https://avatars.githubusercontent.com/u/4178716?v=4)](https://github.com/53ningen "53ningen (1 commits)")[![umihico](https://avatars.githubusercontent.com/u/39179585?v=4)](https://github.com/umihico "umihico (1 commits)")[![amenk](https://avatars.githubusercontent.com/u/1087128?v=4)](https://github.com/amenk "amenk (1 commits)")[![andrii-trush](https://avatars.githubusercontent.com/u/14265776?v=4)](https://github.com/andrii-trush "andrii-trush (1 commits)")[![egs33](https://avatars.githubusercontent.com/u/9857221?v=4)](https://github.com/egs33 "egs33 (1 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (1 commits)")

---

Tags

basic-authenticationlaravellaravel-packagemiddlewarelaravelAuthenticationolssonmhttp basic auth

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/olssonm-l5-very-basic-auth/health.svg)

```
[![Health](https://phpackages.com/badges/olssonm-l5-very-basic-auth/health.svg)](https://phpackages.com/packages/olssonm-l5-very-basic-auth)
```

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M350](/packages/tymon-jwt-auth)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

8359.8M53](/packages/php-open-source-saver-jwt-auth)[laragear/two-factor

On-premises 2FA Authentication for out-of-the-box.

339785.3k8](/packages/laragear-two-factor)[andrewdwallo/filament-companies

A comprehensive Laravel authentication and authorization system designed for Filament, focusing on multi-tenant company management.

34450.0k2](/packages/andrewdwallo-filament-companies)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6712.1k2](/packages/hasinhayder-tyro)[alajusticia/laravel-logins

Session management in Laravel apps, user notifications on new access, support for multiple separate remember tokens, IP geolocation, User-Agent parser

2011.0k](/packages/alajusticia-laravel-logins)

PHPackages © 2026

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