# express-basicauth

> A simple express middleware for basic authentication

Latest version **1.0.2** (published 2017-04-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-basicauth
pnpm add express-basicauth
yarn add express-basicauth
bun add express-basicauth
```

## 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.0.2 |
| Published | 2017-04-05 |
| First published | 2017-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Marius Espejo |
| Maintainers | mariusespejo |

## Links

- npm: https://www.npmjs.com/package/express-basicauth
- Repository: https://github.com/mariusespejo/express-basicauth
- Homepage: https://github.com/mariusespejo/express-basicauth#readme
- Issues: https://github.com/mariusespejo/express-basicauth/issues
- npm.io page: https://npm.io/package/express-basicauth

## Dependencies (2)

- [basic-auth](https://npm.io/package/basic-auth.md) ^1.1.0
- [regenerator-runtime](https://npm.io/package/regenerator-runtime.md) ^0.10.3

## Recent versions

- 1.0.2 (latest) — 2017-04-05
- 1.0.1 — 2017-04-05
- 1.0.0 — 2017-04-05

## README

# express-basicauth 

[![Build Status](https://travis-ci.org/mariusespejo/express-basicauth.svg?branch=master)](https://travis-ci.org/mariusespejo/express-basicauth)

A simple express middleware for basic authentication

## How to install

Install with npm:

```shell
npm install --save express-basicauth
```

## How to use with Express

### This will authenticate if username entered is 'username' and password entered is 'password'.

```javascript
var express = require('express');
var basicAuth = require('express-basicauth');
var app = express();


app.use(basicAuth());
```

### Using a custom username and password:

```javascript
var express = require('express');
var basicAuth = require('express-basicauth');
var app = express();


app.use(basicAuth({username: 'name', password: 'pass' }));
```

### You can also optionally provide your own custom athenticator. 


```javascript
var express = require('express');
var basicAuth = require('express-basicauth');
var app = express();

/**
 * All you need is a function which returns a promise that is resolved once authenticated.
 * You can also use async functions for this 
 */
function myCustomAuthenticator(username, password) {
    let authenticated = false;

    // add authentication logic 

    return authenticated ? Promise.resolve() : Promise.reject();
}

app.use(basicAuth({authenticator: myCustomAuthenticator}));
```

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