npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dmps

v1.0.2

Published

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

Downloads

8

Readme

DMPS

Does My Password Suck!?

Purpose

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'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.

npm i -S dmps
yarn add dmps

Import the Module & Configure

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

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.

const pw = new Dmps(config)

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

Hash Password (pw.hashPassword())

Exposes the internal password hashing method.

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.

  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 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. 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.