argon2 vs bcrypt vs bcrypt-nodejs vs bcryptjs
Password Hashing Libraries
argon2bcryptbcrypt-nodejsbcryptjsSimilar Packages:

Password Hashing Libraries

Password hashing libraries are essential tools in web development for securely storing user passwords. They provide algorithms that transform plaintext passwords into hashed values, making it difficult for attackers to retrieve the original passwords even if they gain access to the database. Each library has its own strengths, weaknesses, and use cases, which can significantly impact the security and performance of an application. Choosing the right library is crucial for maintaining user trust and data integrity in any web application.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
argon202,1211.03 MB87 months agoMIT
bcrypt07,7811.11 MB3010 months agoMIT
bcrypt-nodejs0---13 years ago-
bcryptjs03,788112 kB44 months agoBSD-3-Clause

Feature Comparison: argon2 vs bcrypt vs bcrypt-nodejs vs bcryptjs

Security Strength

  • argon2:

    Argon2 is considered the most secure password hashing algorithm as it won the Password Hashing Competition in 2015. It is designed to be resistant to various attack vectors, including GPU and ASIC attacks, and allows for customizable memory and time costs to enhance security.

  • bcrypt:

    Bcrypt is a strong hashing algorithm that incorporates a work factor, allowing you to adjust the computational cost of hashing. While it is secure, it is not as resistant to modern attacks as Argon2, especially against brute-force attacks using specialized hardware.

  • bcrypt-nodejs:

    Bcrypt-nodejs offers the same security features as Bcrypt, but being a pure JavaScript implementation, it may not be as optimized for performance. It is still secure but may lag behind native implementations in speed.

  • bcryptjs:

    Bcryptjs is a pure JavaScript implementation of Bcrypt, providing similar security features. However, it may not be as fast as native implementations, which could be a concern for applications with high hashing demands.

Performance

  • argon2:

    Argon2 is designed for performance and can be tuned to use more memory and processing time, which can slow down brute-force attacks. However, this configurability means it can be optimized for different environments and use cases, potentially leading to better performance in secure applications.

  • bcrypt:

    Bcrypt is generally slower than other algorithms due to its computational cost, which is a feature designed to enhance security. However, its performance is adequate for most applications, and the work factor can be adjusted to balance security and performance.

  • bcrypt-nodejs:

    Bcrypt-nodejs may have performance issues compared to native Bcrypt implementations, as it is not optimized for speed. This can lead to slower hashing times, especially under heavy load or in high-traffic applications.

  • bcryptjs:

    Bcryptjs, being a pure JavaScript implementation, is slower than native alternatives. It is suitable for smaller applications or those where performance is not the primary concern, but may struggle under high demand.

Ease of Use

  • argon2:

    Argon2 has a straightforward API, but its advanced features may require a deeper understanding of hashing parameters. It is well-documented, making it easier for developers to implement securely.

  • bcrypt:

    Bcrypt is easy to use with a simple API, and its widespread adoption means that many developers are familiar with it. It has extensive documentation and community support, making implementation straightforward.

  • bcrypt-nodejs:

    Bcrypt-nodejs is easy to integrate due to its pure JavaScript nature, which eliminates the need for native bindings. However, it may require additional considerations for performance in production environments.

  • bcryptjs:

    Bcryptjs is also easy to use and integrate, especially for projects that avoid native dependencies. Its simplicity makes it a good choice for developers looking for a lightweight solution.

Community and Support

  • argon2:

    Argon2 is gaining popularity and has a growing community, but it may not have as extensive support as older libraries. Its modern approach means that resources and examples are increasing but may still be limited compared to more established libraries.

  • bcrypt:

    Bcrypt has a large community and extensive documentation, making it one of the most supported password hashing libraries available. There are numerous resources, tutorials, and community contributions that can help developers implement it effectively.

  • bcrypt-nodejs:

    Bcrypt-nodejs has a smaller community compared to Bcrypt, but it is still supported by many developers. However, resources and examples may not be as plentiful as those for Bcrypt.

  • bcryptjs:

    Bcryptjs has a decent community and is well-documented, but it may not have the same level of support as Bcrypt. It is still a viable option for developers looking for a pure JavaScript solution.

Compatibility

  • argon2:

    Argon2 is compatible with modern environments and is supported by various programming languages. However, it may require additional libraries or dependencies in some cases, depending on the implementation.

  • bcrypt:

    Bcrypt is widely compatible across different platforms and programming languages, making it a safe choice for most applications. It has been integrated into many frameworks and libraries, ensuring broad support.

  • bcrypt-nodejs:

    Bcrypt-nodejs is designed to work in environments where native bindings are not feasible, making it a good choice for JavaScript-only projects. However, its performance may vary depending on the environment.

  • bcryptjs:

    Bcryptjs is compatible with any JavaScript environment, including Node.js and browsers. Its pure JavaScript nature allows for easy integration without worrying about native dependencies.

How to Choose: argon2 vs bcrypt vs bcrypt-nodejs vs bcryptjs

  • argon2:

    Choose Argon2 if you need the most secure and modern hashing algorithm available. It is designed to resist GPU-based attacks and is highly configurable, allowing you to adjust memory usage and execution time to balance security and performance.

  • bcrypt:

    Choose Bcrypt if you are looking for a widely adopted and well-tested solution that has been around for years. It is suitable for most applications and provides a good balance between security and performance, although it may not be as resistant to certain types of attacks as Argon2.

  • bcrypt-nodejs:

    Choose Bcrypt-nodejs if you prefer a pure JavaScript implementation of Bcrypt that does not require native bindings, making it easier to use in environments where native compilation is not feasible. However, it may have performance drawbacks compared to native implementations.

  • bcryptjs:

    Choose Bcryptjs if you need a pure JavaScript implementation of Bcrypt that is lightweight and easy to integrate into your project. It is suitable for applications where you want to avoid native dependencies, but it may be slower than native alternatives.

README for argon2

node-argon2

Financial contributors on Open Collective Build status NPM package

Bindings to the reference Argon2 implementation.

Usage

It's possible to hash using either Argon2i, Argon2d or Argon2id (default), and verify if a password matches a hash.

To hash a password:

const argon2 = require('argon2');

try {
  const hash = await argon2.hash("password");
} catch (err) {
  //...
}

To see how you can modify the output (hash length, encoding) and parameters (time cost, memory cost and parallelism), read the wiki

To verify a password:

try {
  if (await argon2.verify("<big long hash>", "password")) {
    // password match
  } else {
    // password did not match
  }
} catch (err) {
  // internal failure
}

Migrating from another hash function

See this article on the wiki for steps on how to migrate your existing code to Argon2. It's easy!

TypeScript usage

A TypeScript type declaration file is published with this module. If you are using TypeScript 2.0.0 or later, that means you do not need to install any additional typings in order to get access to the strongly typed interface. Simply use the library as mentioned above.

import * as argon2 from "argon2";

const hash = await argon2.hash(..);

Prebuilt binaries

node-argon2 provides prebuilt binaries from v0.26.0 onwards. They are built every release using GitHub Actions.

The current prebuilt binaries are built and tested with the following systems:

  • Ubuntu 22.04 (x86-64; ARM64 from v0.28.2; ARMv7 from v0.43.0)
  • MacOS 13 (x86-64)
  • MacOS 14 (ARM64 from v0.29.0)
  • Windows Server 2022 (x86-64)
  • Alpine Linux 3.18 (x86-64 from v0.28.1; ARM64 from v0.28.2; ARMv7 from v0.43.0)
  • FreeBSD 14 (x86-64 from v0.29.1; ARM64 from v0.44.0)

Binaries should also work for any version more recent than the ones listed above. For example, the binary for Ubuntu 20.04 also works on Ubuntu 22.04, or any other Linux system that ships a newer version of glibc; the binary for MacOS 11 also works on MacOS 12. If your platform is below the above requirements, you can follow the Before installing section below to manually compile from source. It is also always recommended to build from source to ensure consistency of the compiled module.

Before installing

You can skip this section if the prebuilt binaries work for you.

You MUST have a node-gyp global install before proceeding with the install, along with GCC >= 5 / Clang >= 3.3. On Windows, you must compile under Visual Studio 2015 or newer.

node-argon2 works only and is tested against Node >=18.0.0.

OSX

To install GCC >= 5 on OSX, use homebrew:

$ brew install gcc

Once you've got GCC installed and ready to run, you then need to install node-gyp, you must do this globally:

$ npm install -g node-gyp

Finally, once node-gyp is installed and ready to go, you can install this library, specifying the GCC or Clang binary to use:

$ CXX=g++-12 npm install argon2

NOTE: If your GCC or Clang binary is named something different than g++-12, you'll need to specify that in the command.

FAQ

How do I manually rebuild the binaries?
$ npx @mapbox/node-pre-gyp rebuild -C ./node_modules/argon2

Run @mapbox/node-pre-gyp instead of node-gyp because node-argon2's binding.gyp file relies on variables from @mapbox/node-pre-gyp.

You can omit npx @mapbox and use just node-pre-gyp if you have a global installation of @mapbox/node-pre-gyp, otherwise prefixing npx will use the local one in ./node_modules/.bin

How do I skip installing prebuilt binaries and manually compile from source?

You can do either of the two methods below:

  1. Force build from source on install.
$ npm install argon2 --build-from-source
  1. Ignore node-argon2 install script and build manually.
$ npm install argon2 --ignore-scripts
$ npx node-gyp rebuild -C ./node_modules/argon2
I installed Node as a snap, and I can't install node-argon2.

This seems to be an issue related to snap (see #345 (comment)). Installing Node with another package manager, such as asdf or nvm, is a possible workaround.

Contributors

Code contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

Work licensed under the MIT License. Please check P-H-C/phc-winner-argon2 for license over Argon2 and the reference implementation.