<commit_before># http-auth
[Node.js](http://nodejs.org/) package for HTTP basic and digest access authentication.

[![build](https://github.com/http-auth/http-auth/workflows/build/badge.svg)](https://github.com/http-auth/http-auth/actions?query=workflow%3Abuild)

## Installation

Via git (or downloaded tarball):

```bash
$ git clone git://github.com/http-auth/http-auth.git
```
Via [npm](http://npmjs.org/):

```bash
$ npm install http-auth
```	

## Basic example
```javascript
// Authentication module.
var auth = require('http-auth');
var basic = auth.basic({
	realm: "Simon Area.",
	file: __dirname + "/../data/users.htpasswd"
});

// Creating new HTTP server.
http.createServer(basic.check((req, res) => {
	res.end(`Welcome to private area - ${req.user}!`);
})).listen(1337);

```
## Custom authentication
```javascript	
// Authentication module.
var auth = require('http-auth');
var basic = auth.basic({
		realm: "Simon Area."
	}, (username, password, callback) => { 
	    // Custom authentication
	    // Use callback(error) if you want to throw async error.
		callback(username === "Tina" && password === "<PASSWORD>");
	}
);

// Creating new HTTP server.
http.createServer(basic.check((req, res) => {
	res.end(`Welcome to private area - ${req.user}!`);
})).listen(1337);
```

## Events

The auth middleware emits three types of events: **error**, **fail** and **success**. Each event passes the result object (the error in case of `fail`) and the http request `req` to the listener function.

```javascript
// Authentication module.
var auth = require('http-auth');
var basic = auth.basic({
    realm: "Simon Area.",
    file: __dirname + "/../data/users.htpasswd"
});

basic.on('success', (result, req) => {
	console.log(`User authenticated: ${result.user}`);
});

basic.on('fail', (result, req) => {
	console.log(`User authentication failed: ${result.user}`);
});

basic.on('error', (error, req) => {
	console.log(`Authentication error: ${error.code + " - " + error.message}`);
});
```

## Configurations

 - `realm` - Authentication realm, by default it is **Users**.
 - `file` - File where user details are stored.
 	- Line format is **{user:pass}** or **{user:passHash}** for basic access. 
 	- Line format is **{user:realm:passHash}** for digest access.
 - `algorithm` - Algorithm that will be used only for **digest** access authentication.
 	- **MD5** by default.
 	- **MD5-sess** can be set.
 - `qop` - Quality of protection that is used only for **digest** access authentication.
 	- **auth** is set by default.
 	- **none** this option is disabling protection.
 - `msg401` - Message for failed authentication 401 page.
 - `msg407` - Message for failed authentication 407 page.
 - `contentType` - Content type for failed authentication page.
 - `skipUser` - Set this to **true**, if you don't want req.user to be filled with authentication info.

## Running tests

It uses [mocha](https://mochajs.org/), so just run following command in package directory:

```bash
$ npm test
```

## Issues

You can find list of issues using **[this link](http://github.com/http-auth/http-auth/issues)**.

## Questions

You can also use [stackoverflow](http://stackoverflow.com/questions/tagged/http-auth) to ask questions using **[http-auth](http://stackoverflow.com/tags/http-auth/info)** tag.

## Requirements

 - **[Node.js](http://nodejs.org)** - Event-driven I/O server-side JavaScript environment based on V8.
 - **[npm](http://npmjs.org)** - Package manager. Installs, publishes and manages node programs.

## Utilities

 - **[htpasswd](https://github.com/http-auth/htpasswd/)** - Node.js package for HTTP Basic Authentication password file utility.
 - **[htdigest](https://github.com/http-auth/htdigest/)** - Node.js package for HTTP Digest Authentication password file utility.

## Integrations

 - **[http-auth-koa](https://github.com/http-auth/http-auth-koa)** - [Koa framework](http://koajs.com/) integration with [http-auth](https://github.com/http-auth/http-auth) module.
 - **[http-auth-hapi](https://github.com/http-auth/http-auth-hapi)** - [Hapi framework](https://hapi.dev/) integration with [http-auth](https://github.com/http-auth/http-auth) module.


## Dependencies

 - **[uuid](https://github.com/broofa/node-uuid/)** - Generate RFC4122(v4) UUIDs, and also non-RFC compact ids.
 - **[apache-md5](https://github.com/http-auth/apache-md5)** - Node.js module for Apache style password encryption using md5.
 - **[apache-crypt](https://github.com/http-auth/apache-crypt)** - Node.js module for Apache style password encryption using crypt(3).
 - **[bcrypt.js](https://github.com/dcodeIO/bcrypt.js)** - Optimized bcrypt in plain JavaScript with zero dependencies.

## License

The MIT License (MIT)

Copyright (c) <NAME>
<commit_msg>Readme adjusted.<commit_after># http-auth
[Node.js](http://nodejs.org/) package for HTTP basic and digest access authentication.

[![build](https://github.com/http-auth/http-auth/workflows/build/badge.svg)](https://github.com/http-auth/http-auth/actions?query=workflow%3Abuild)

## Installation

Via git (or downloaded tarball):

```bash
$ git clone git://github.com/http-auth/http-auth.git
```
Via [npm](http://npmjs.org/):

```bash
$ npm install http-auth
```	

## Basic example
```javascript
// Authentication module.
var auth = require('http-auth');
var basic = auth.basic({
	realm: "Simon Area.",
	file: __dirname + "/../data/users.htpasswd"
});

// Creating new HTTP server.
http.createServer(basic.check((req, res) => {
	res.end(`Welcome to private area - ${req.user}!`);
})).listen(1337);

```
## Custom authentication
```javascript	
// Authentication module.
var auth = require('http-auth');
var basic = auth.basic({
		realm: "Simon Area."
	}, (username, password, callback) => { 
	    // Custom authentication
	    // Use callback(error) if you want to throw async error.
		callback(username === "Tina" && password === "<PASSWORD>");
	}
);

// Creating new HTTP server.
http.createServer(basic.check((req, res) => {
	res.end(`Welcome to private area - ${req.user}!`);
})).listen(1337);
```

## Events

The auth middleware emits three types of events: **error**, **fail** and **success**. Each event passes the result object (the error in case of `fail`) and the http request `req` to the listener function.

```javascript
// Authentication module.
var auth = require('http-auth');
var basic = auth.basic({
    realm: "Simon Area.",
    file: __dirname + "/../data/users.htpasswd"
});

basic.on('success', (result, req) => {
	console.log(`User authenticated: ${result.user}`);
});

basic.on('fail', (result, req) => {
	console.log(`User authentication failed: ${result.user}`);
});

basic.on('error', (error, req) => {
	console.log(`Authentication error: ${error.code + " - " + error.message}`);
});
```

## Configurations

 - `realm` - Authentication realm, by default it is **Users**.
 - `file` - File where user details are stored.
 	- Line format is **{user:pass}** or **{user:passHash}** for basic access. 
 	- Line format is **{user:realm:passHash}** for digest access.
 - `algorithm` - Algorithm that will be used only for **digest** access authentication.
 	- **MD5** by default.
 	- **MD5-sess** can be set.
 - `qop` - Quality of protection that is used only for **digest** access authentication.
 	- **auth** is set by default.
 	- **none** this option is disabling protection.
 - `msg401` - Message for failed authentication 401 page.
 - `msg407` - Message for failed authentication 407 page.
 - `contentType` - Content type for failed authentication page.
 - `skipUser` - Set this to **true**, if you don't want req.user to be filled with authentication info.

## Running tests

It uses [mocha](https://mochajs.org/), so just run following command in package directory:

```bash
$ npm test
```

## Issues

You can find list of issues using **[this link](http://github.com/http-auth/http-auth/issues)**.

## Questions

You can also use [stackoverflow](http://stackoverflow.com/questions/tagged/http-auth) to ask questions using **[http-auth](http://stackoverflow.com/tags/http-auth/info)** tag.

## Requirements

 - **[Node.js](http://nodejs.org)** - Event-driven I/O server-side JavaScript environment based on V8.
 - **[npm](http://npmjs.org)** - Package manager. Installs, publishes and manages node programs.

## Utilities

 - **[htpasswd](https://github.com/http-auth/htpasswd/)** - Node.js package for HTTP Basic Authentication password file utility.
 - **[htdigest](https://github.com/http-auth/htdigest/)** - Node.js package for HTTP Digest Authentication password file utility.

## Integrations

 - **[http-auth-koa](https://github.com/http-auth/http-auth-koa)** - [Koa framework](http://koajs.com/) integration.
 - **[http-auth-hapi](https://github.com/http-auth/http-auth-hapi)** - [Hapi framework](https://hapi.dev/) integration.


## Dependencies

 - **[uuid](https://github.com/broofa/node-uuid/)** - Generate RFC4122(v4) UUIDs, and also non-RFC compact ids.
 - **[apache-md5](https://github.com/http-auth/apache-md5)** - Node.js module for Apache style password encryption using md5.
 - **[apache-crypt](https://github.com/http-auth/apache-crypt)** - Node.js module for Apache style password encryption using crypt(3).
 - **[bcrypt.js](https://github.com/dcodeIO/bcrypt.js)** - Optimized bcrypt in plain JavaScript with zero dependencies.

## License

The MIT License (MIT)

Copyright (c) <NAME>

{'fraction_non_alphanumeric': 0.17801214445509747, 'fraction_numerical': 0.007031000319590924, 'mean_word_length': 4.066378845116028, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 26, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4240545', 'n_tokens_mistral': 3063, 'n_tokens_neox': 2880, 'n_words': 835}