@keeex/pwdcheck
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@keeex/pwdcheck

Small SDK to interrogate the HIBP password database or a proxy.

Getting started

The following three functions provides quick access to the password checker:

import {apiFactory, memoryCacheFactory, nodeFsCacheFactory} from "@keeex/pwdcheck";

// Usable anywhere axios is supported
const checker = apiFactory();

// Usable anywhere if you want to cache queries
const checker = await memoryCacheFactory();

// Usable only in node, use FS to cache queries
const checker = await nodeFsCacheFactory();

// Use the check function
const pwdLeaked = await checker.isPasswordLeaked("bonjour123");

Detailed usage

Instantiate PasswordChecker with the function used to query the API. To create a function that query the API directly, use makeApiGetter(). To add a level of cache, use either memoryCache() or nodeFsCache().

Proxy server using Express

To implement a service that provides an appropriate reply to this SDK, you can leverage the provided cache and getter mechanism.

A basic service would look like this:

import express from "express";
import {makeApiGetter} from "@keeex/pwdcheck/lib/apigetter.js";
import {nodeFsCache} from "@keeex/pwdcheck/lib/cache/nodefs.js";

const app = express();

// Usable only in node, use FS to cache queries
const apiGetter = makeApiGetter({remoteServer: hibpEndpoint});
const cacheGetter = nodeFsCache(apiGetter, {cachePath: "hibpcache"});

// Use the check function
app.get("/password/:prefix([0-9a-fA-F]{5})", (req, res, next) => {
  (async () => {
    res.send(await cacheGetter(req.params.prefix.toUpperString()));
  })().catch(next);
});

The above example would handle requests sent to https://server/password/ABCDE as a proxy to the HIBP service, and cache the result in the hibpcache directory for a day (the default setting). (note that the HIBP API is on /range/ABCDE)

The same SDK can be pointed to this endpoint and work as expected.

Readme

Keywords

none

Package Sidebar

Install

npm i @keeex/pwdcheck

Weekly Downloads

62

Version

1.0.2

License

MIT

Unpacked Size

63.9 kB

Total Files

31

Last publish

Collaborators

  • keeex_jenkins
  • marc-keeex
  • cley_faye