# s-salt-pepper

> Password hashing (via pbkdf2) with salt and pepper

Latest version **3.0.4** (published 2018-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install s-salt-pepper
pnpm add s-salt-pepper
yarn add s-salt-pepper
bun add s-salt-pepper
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.4 |
| Published | 2018-01-26 |
| First published | 2015-04-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/s-salt-pepper) |
| Module format | CommonJS |
| Node | >= 8 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | sebastian sandqvist |
| Maintainers | seabass |
| Keywords | password, hash, salt, pepper, random, iterations, pbkdf2, javascript, node |

## Links

- npm: https://www.npmjs.com/package/s-salt-pepper
- Repository: https://github.com/sebastiansandqvist/s-salt-pepper
- Issues: https://github.com/sebastiansandqvist/s-salt-pepper/issues
- npm.io page: https://npm.io/package/s-salt-pepper

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 3.0.4 (latest) — 2018-01-26
- 3.0.3 — 2018-01-26
- 3.0.2 — 2018-01-26
- 3.0.1 — 2018-01-25
- 3.0.0 — 2018-01-25
- 2.1.0 — 2016-04-23
- 2.0.2 — 2015-06-23
- 2.0.1 — 2015-06-23
- 1.0.3 — 2015-04-16
- 1.0.0 — 2015-04-16
- 0.1.5 — 2015-04-16
- 0.1.4 — 2015-04-13
- 0.1.3 — 2015-04-13
- 0.1.2 — 2015-04-13
- 0.1.1 — 2015-04-13
- … 2 more at https://npm.io/package/s-salt-pepper/versions

## README

# s-salt-pepper
[![NPM version](https://img.shields.io/npm/v/s-salt-pepper.svg)](https://www.npmjs.com/package/s-salt-pepper) ![Dependencies](https://img.shields.io/david/sebastiansandqvist/s-salt-pepper.svg) [![build status](http://img.shields.io/travis/sebastiansandqvist/s-salt-pepper.svg)](https://travis-ci.org/sebastiansandqvist/s-salt-pepper) [![NPM license](https://img.shields.io/npm/l/s-salt-pepper.svg)](https://www.npmjs.com/package/s-salt-pepper) ![Stability](https://img.shields.io/badge/stability-stable-green.svg)

## About
This dependency-free module provides password hashing and comparison with salt and variable iterations of pbkdf2. An additional "pepper" (optional) is concatenated to the salt before hashing. The salts are kept in your database, the pepper is saved on your server. Works with node versions 8 and above.

## Installation
```bash
npm install s-salt-pepper
```

## Usage
1. Generate a password hash with a salt (for example, when a user signs up) using `password.hash()`
2. Whenever the user logs in or needs to verify their password, compare the provided login password with the user's saved salt and hash using `password.compare()`

```js
const password = require('s-salt-pepper');

// configure once
password.iterations(75000); // optionally set number of pbkdf2 iterations
password.pepper('your random string goes here');

// hash a string and save returned salt and hash to (fake) user
const user = {
  password: {
    hash: null,
    salt: null
  }
};

async () => {
  // set the user's password to { hash: String, salt: String }
  user.password = await password.hash('foo');

  // ...later, verify that a given string matches the user's password data
  await password.compare('bar', user.password); // false
  await password.compare('foo', user.password); // true
}
```

## API
#### `async password.hash(String)`
Accepts a string password argument, returns a promise that resolves to an object of the shape:
```js
{
  hash: String,
  salt: String
}
```

#### `async password.compare(String, { hash: String, salt: String })`
Accepts a string password as the first argument and an object like the one given by `password.hash()` as the second argument. Returns a promise that resolves to `true` if the password is a match, `false` otherwise.

#### `password.saltLength(Number?)`
Returns the salt length if called without any arguments. Sets the salt length (in bytes, before base64 conversion) if called with one argument.

#### `password.iterations(Number?)`
Returns the number of pbkdf2 iterations to run if called without any arguments. Sets the number of pbkdf2 iterations if called with one argument.

#### `password.keyLength(Number?)`
Returns the pbkdf2 key length if called without any arguments. Sets the key length (in bytes, before base64 conversion) if called with one argument.

#### `password.digest(String?)`
Returns the pbkdf2 digest algorithm if called without any arguments. Sets the digest algorithm if called with one argument.

#### `password.pepper(String?)`
Returns the pepper if called without any arguments. Sets the pepper if called with one argument.

## Config options
The following can be configured (defaults displayed below):
```js
password.saltLength(32);
password.iterations(100000); // ~200ms to compute with current key/salt lengths
password.keyLength(128);
password.digest('sha512');
password.pepper('');
```

Calling those functions without any arguments returns their current value.
```js
password.saltLength(); // => 32
```

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