Giter VIP home page Giter VIP logo

pwnedpasswords's Introduction

pwnedpasswords

Travis npm Known Vulnerabilities

A dependency-free Node.js module for interfacing with the PwnedPasswords API by Troy Hunt (haveibeenpwned.com).

This module implements the new and improved version 2 of the API. This version of the API implements k-Anonymity and does NOT send even the hashed version of the passwords to third party. It only sends the first 5 characters of the SHA-1 hash. You can read more about it in the Troy Hunt's blog announcement post.

The reason I chose not to use any dependencies (e.g. request or got) is first, because it is a pretty simple API and can be handled easily by the built-in https module. But mainly, it is for security reasons. Dependency chain can get deep and unpredictable. One rogue module down the chain can intercept requests and hand over passwords elsewhere.

Installation

Please review the code before use.

Install and save exact module version, to avoid installing, another, potentially vulnerable version in the future.

If you need to upgrade, again, review the code and upgrade to an exact version you have witnessed yourself.

npm install --save-exact pwnedpasswords

Usage

The module implements three interfaces. Callback, promises and CLI.

Return value is an integer with a count of input password prevalence.

Zero (0) is returned when the password is not found.

Promises

const pwnedpasswords = require('pwnedpasswords')

pwnedpasswords('password')
  .then(count => {
    console.log('Password was found %d times.', count)
  })
  .catch(err => {
    console.error(err)
  })

Callback

const pwnedpasswords = require('pwnedpasswords')

pwnedpasswords('password', (err, count) => {
  if (err) {
    console.error(err)
  }

  console.log('Password was found %d times.', count)
})

CLI

It is not recommended to use this command with real passwords, as you are exposing the password to the process list and shell history. But this can be used for testing and educational scenarios or in other shell scripts.

$> ./node_modules/.bin/pwnedpasswords password
3730471

Or if installed globally, then run:

$> pwnedpasswords password
3730471

Or via npx:

$> npx -q pwnedpasswords password
3730471

Dependencies

None

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.