try { if (await argon2.verify("<big long hash>", "password")) { // password match } else { // password did not match }} catch (err) { // internal failure}
[!NOTE]
By default, argon2.hash will generate secure hashes according to the security recommendations by the team that develops Argon2.
For password hashing, there is no need to modify them.
To see how you can modify the output (hash length, encoding) and parameters
(time cost, memory cost and parallelism),
read the wiki
Comparison with the node:crypto native implementation
The native API is focused towards generic usage of the Argon2 hash function, while this package historically focused on password hashing.
Once all supported Node releases include native Argon2 and older versions are officially EOL, node-argon2 will transition into a minimal wrapper. It will offer the most developer-friendly interface, bridging users to Node's native crypto methods. This avoids duplication and ensures seamless upgrades once native support is universal.
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.
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 >=22.0.0.
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:
Force build from source on install.
$ npm install argon2 --build-from-source
Ignore node-argon2 install script and build manually.
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]