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

protect-password

v1.0.3

Published

Secure password hashing and verification utilities using PBKDF2 and timingSafeEqual.

Downloads

22

Readme

protect-password

protect-password is a lightweight, dependency-free JavaScript library for securely hashing passwords and verifying password hashes using PBKDF2 with sha512. It provides a secure way to protect passwords and uses timing-safe comparison to prevent timing attacks.

Why You Need This

When building secure applications, password security is critical. Hashing passwords ensures that even if the password database is compromised, the plaintext passwords are not exposed.

This library helps you:

  • Securely hash passwords using PBKDF2 (Password-Based Key Derivation Function 2) with sha512.
  • Safely verify passwords using constant-time comparisons to avoid timing attacks.

Security and Performance

This package uses the PBKDF2 algorithm with a sha512 hash, which is recommended by NIST (National Institute of Standards and Technology). PBKDF2 is a password-stretching mechanism that adds computational effort, making brute-force attacks much harder.

protect-password defaults to 1,000,000 iterations, which balances security and performance. You can modify the iteration count based on your specific needs, but we recommend sticking with our default, which will increase with future releases.

Future Enhancements

In the future, we plan to add options for algorithms such as:

  • scrypt: A memory-hard password hashing function.
  • Argon2: The winner of the Password Hashing Competition, designed for security and performance.

Note: Argon2 may require using a third-party library until Node.js adds built-in support.

How to Use

Install the package

npm install protect-password

If you are using TypeScript, install the type definitions as well:

npm install protect-password-types

Protect a Password

const { protect } = require("protect-password");

const password = "mysecretpassword";
const protectedHash = protect(password);
console.log(protectedHash); // Output: pbkdf2_sha512$1000000$salt$hash

Verify a Password

const { verify } = require("protect-password");

const password = "mysecretpassword";
const storedHash = "pbkdf2_sha512$1000000$salt$hash";

const isValid = verify(password, storedHash);
console.log(isValid); // Output: true or false

Customizing Iterations

By default, protect-password uses 1,000,000 iterations. You can modify this based on your security requirements:

const { protect } = require("protect-password");

const options = { iterations: 500_000 };
const protectedHash = protect("mysecretpassword", options);

However, we recommend using the default as it offers robust security. Future releases will increment the default iteration count as computing power increases.

License

This project is licensed under the MIT License. Feel free to fork it, extend it, and use it in your projects.