# dmps

> Does My Password Suck — Utility to safely check the HaveIBeenPwned "Pwned Passwords" database in the browser.

Latest version **1.0.2** (published 2019-05-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install dmps
pnpm add dmps
yarn add dmps
bun add dmps
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-05-28 |
| First published | 2019-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 28.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Will Hackett |
| Maintainers | willhackett |

## Links

- npm: https://www.npmjs.com/package/dmps
- Repository: https://github.com/willhackett/dmps-js
- Homepage: https://github.com/willhackett/dmps-js#readme
- Issues: https://github.com/willhackett/dmps-js/issues
- npm.io page: https://npm.io/package/dmps

## Recent versions

- 1.0.2 (latest) — 2019-05-28
- 1.0.1 — 2019-05-26

## README

# DMPS

##### Does My Password Suck!?

## Purpose

[Credential stuffing](https://www.owasp.org/index.php/Credential_stuffing) is a very real threat to web application security and it's important that businesses are doing their best to protect their users from passwords that been been seen in known breaches.

This library is designed to be hooked into your *login* or *change password* forms to ensure that users aren't using or setting passwords seen in known breaches. This is achieved by sending the first five characters of a SHA-1 copy of the user's password to [Have I Been Pwned](https://haveibeenpwned.com/API/v2)'s API and matching it against the result set that is returned.

TL;DR: This adds breached password detection to your web apps.

#### Note: This library is intended for browser use only. In future versions it might support Node but the intent is to keep the library free from dependencies.

## Installation

Install the `dmps` package using `npm` or `yarn`.

```bash
npm i -S dmps
```

```bash
yarn add dmps
```
### Import the Module & Configure

Import the module and instantiate the class. TypeScript types are available.

```typescript
import Dmps from 'dmps'

const pw = new Dmps(config)
```

## Methods

### Check Password (`pw.check()`)

pw.check returns a promise that resolves `true` or reject with an `Error`. See *Error Handling* below.

```typescript
const pw = new Dmps(config)

pw.check('password') // Promise<true>

```

### Hash Password (`pw.hashPassword()`)

Exposes the internal password hashing method.

```typescript
const pw = new Dmps(config)

pw.hashPassword('password') // '5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8'

```

## Error Handling

Methods in the `dmps` library use custom errors so you can better handle responses.

```typescript
  try {
    await pw.check('password')
  } catch (e) {
    switch(e.name) {
      case 'UnexpectedHttpResponseError':
        // A response other than 200 was received from HIBP
      case 'TimedOutError':
        // The timeout was reached
      case 'InvalidPasswordError':
        // The password is either not a string or is empty
      case 'BreachedError':
        // The password has been breached
        // You can use e.count on this error type
        console.log(`Password has been breached ${e.count} times.`)
    }
  }
```

## Configuration

DMPS can be configured accordingly:

| Option             | Type                 | Default                                           | Purpose                                                 |
| :------------------|:---------------------|:--------------------------------------------------|:------------------------------------------------------- |
| `endpoint`         | `string` (optional)  | `https://api.pwnedpasswords.com/range/`           | Substitute the HIBP endpoit for your own.               |
| `timeout`          | `number` (optional)  | `5000`                                            | Timeout on the check.                                   |
| `userAgent`        | `string` (optional)  | `dmps-js`                                         | Change the UserAgent to represent your service.         |
| `resolveOnTimeout` | `boolean` (optional) | `false`                                           | Resolve instead of erroring on timeout.                 |

### `endpoint`

In some environments a business may choose to either proxy or host their own HIBP endpoint. The script will pass the first five characters of the SHA-1'd password to the last url part — for example: `https://api.pwnedpasswords.com/range/{hash}`

### `timeout`

To ensure that the user experience isn't adversely affected by the additional HTTP request it is recommended to set a timeout. The default timeout is `5000` milliseconds, but you may want to change this depending on your situation. 

### `userAgent`

The [HIBP API Acceptable Use Policy](https://haveibeenpwned.com/API/v2#AcceptableUse) requires that user agent "accurately describe the nature of the API consumer such that it can be clearly identified in the request". It is recommended that you change this, however it will default to `dmps-js`.

Please also refer to the licensing requirements for using the [Passwords API](https://haveibeenpwned.com/API/v2#License). Accreditation isn't required but it is welcomed by HIBP.

### `resolveOnTimeout`

Setting this to `true` will resolve the `check` method promise if it times out which can assist in some programming situations. This is not recommended as you should try and handle this in your codebase.

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