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

@sequencemedia/pbkdf2

v1.0.373

Published

## Compare a given password to a `hash` and `salt`

Downloads

1,633

Readme

@sequencemedia/pbkdf2

Compare a given password to a hash and salt

Exposes the crypto pbkdf2 utilities as async functions for Node and the shell

ES functions are exported from the package root alongside a TS definition

Password validation by hash and salt comparison

A password can be compared with a hash and salt (and the number of iterations that were used to compute it) to determine whether it is valid

The ES functions expect the same argument types as the underlying Node utilities

  • The hash is a Buffer
  • The salt is a Buffer
  • iterations is a Number
  • keylen is a Number
  • digest is a String

Etc.

compare

The password is expected as the first argument, while the others are fields on a params object

const isValid = await compare(password, {
  hash,
  salt,
  iterations,
  keylen,
  digest
})

hash

As with compare, the password is expected as the first argument, while the others are fields on a params object (except for hash which can of course be omitted)

const value = await hash(password, {
  hash,
  iterations,
  keylen,
  digest
})

salt

An async wrapper around crypto.randomBytes() to generate a salt of the salt size

const value = await salt(size)

In the shell

Scripts are exposed to npm in the package and each script can of course be invoked from the command line directly in the shell

{
  "compare": "node scripts/compare.mjs",
  "hash": "node scripts/hash.mjs",
  "salt": "node scripts/salt.mjs"
}

Where required, both the hash and salt arguments are expected from the command line to be strings in Base64 format. Both iterations and keylen are coerced from strings to numbers

npm run compare -- \
  --password <PASSWORD> \
  --hash <HASH> \
  --salt <SALT> \
  --keylen <KEY LENGTH> \
  --iterations <ITERATIONS> \
  --digest <DIGEST>
node ./scripts/compare.mjs \
  --password <PASSWORD> \
  --hash <HASH> \
  --salt <SALT> \
  --keylen <KEY LENGTH> \
  --iterations <ITERATIONS> \
  --digest <DIGEST>

Etc.

  • The hash is decoded from a Base64 String to a Buffer
  • The salt is decoded from a Base64 String to a Buffer

Tests

npm test
./compare.sh