# basic-authentication

> http basic authentication

Latest version **1.10.0** (published 2017-12-31) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install basic-authentication
pnpm add basic-authentication
yarn add basic-authentication
bun add basic-authentication
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.10.0 |
| Published | 2017-12-31 |
| First published | 2014-06-13 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | hex7c0 |
| Maintainers | hex7c0 |
| Keywords | basic, basic-auth, authentication, authorization |

## Links

- npm: https://www.npmjs.com/package/basic-authentication
- Repository: https://github.com/hex7c0/basic-authentication
- Issues: https://github.com/hex7c0/basic-authentication/issues
- npm.io page: https://npm.io/package/basic-authentication

## Dependencies (1)

- [setheaders](https://npm.io/package/setheaders.md) 0.4.0

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.10.0 (latest) — 2017-12-31
- 1.9.0 — 2017-05-14
- 1.8.0 — 2016-12-22
- 1.7.0 — 2016-09-12
- 1.6.2 — 2015-11-26
- 1.6.1 — 2015-09-26
- 1.6.0 — 2015-08-19
- 1.5.12 — 2015-02-28
- 1.5.11 — 2015-02-04
- 1.5.10 — 2015-01-19
- 1.5.9 — 2014-11-17
- 1.5.8 — 2014-10-26
- 1.5.7 — 2014-10-04
- 1.5.6 — 2014-09-01
- 1.5.5 — 2014-08-31
- … 20 more at https://npm.io/package/basic-authentication/versions

## README

# [basic-authentication](https://github.com/hex7c0/basic-authentication)

[![NPM version](https://img.shields.io/npm/v/basic-authentication.svg)](https://www.npmjs.com/package/basic-authentication)
[![Linux Status](https://img.shields.io/travis/hex7c0/basic-authentication.svg?label=linux-osx)](https://travis-ci.org/hex7c0/basic-authentication)
[![Windows Status](https://img.shields.io/appveyor/ci/hex7c0/basic-authentication.svg?label=windows)](https://ci.appveyor.com/project/hex7c0/basic-authentication)
[![Dependency Status](https://img.shields.io/david/hex7c0/basic-authentication.svg)](https://david-dm.org/hex7c0/basic-authentication)
[![Coveralls](https://img.shields.io/coveralls/hex7c0/basic-authentication.svg)](https://coveralls.io/r/hex7c0/basic-authentication)

Basic authentication is method for a HTTP user agent to provide a user name and password.

## Installation

Install through NPM

```bash
npm install basic-authentication
```
or
```bash
git clone git://github.com/hex7c0/basic-authentication.git
```

## API

inside expressjs project like a middleware
```js
var authentication = require('basic-authentication')();

var app = require('express')();
app.use(authentication);
```
inside expressjs project like a callback for certain route
```js
var authentication = require('basic-authentication')();

var app = require('express')();
app.get('/', authentication, function(req, res) {

    res.send('ok');
});
```
inside routing like a function
```js
var authentication = require('basic-authentication')({functions: true});

var app = require('express')();
app.get('/', function(req, res) {

    var user = authentication(req);
    if (user == 'foo') {
        res.send('ok');
    } else {
        res.send('ko');
    }
});
```

### authentication(options)

#### options

 - `user` - **String** User for web basic access authentication *(default "admin")*
 - `password` - **String** Password for web basic access authentication *(default "password")*
 - `file` - **String** Path of htpasswd file *(default "disabled")*
 - `hash` - **String** Type of [hash](http://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm) inside your htpasswd file *(default "md5")*
 - `agent` - **String** Browser User Agent for web authentication *(default "all accepted")*
 - `realm` - **String** Realm for web authentication *(default "Authorization required")*
 - `ending` - **Boolean** Flag for send `res.end` (response) to client after error or wrong password (not in "functions" mode) *(default "true")*
 - `functions` - **Boolean** Flag for using module like a function *(default "false")*
 - `legacy` - **Boolean** Flag for using module like a function that return an Object *(default "false")*
 - `suppress` - **Boolean** Suppress all routing error *(default "false")*

in `functions` mode, it return a Base64 **String**; otherwise, if some errors occurred, return an Empty **String**

in `legacy` mode, it return an **Object** `{user, password}`; otherwise, if some errors occurred, return an Empty **Object**

## Examples

Take a look at my [examples](examples)

### [License Apache2](LICENSE)

---
_Source: https://npm.io/package/basic-authentication · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
