bcrypt
Node.js library for hashing and verifying passwords with the bcrypt adaptive hashing algorithm.
Official Documentation ↗v6.0.0. Check the official docs for the latest API surface.Installation
npm install bcryptpnpm add bcryptyarn add bcryptMethods
No methods match this filter.
bcrypt is a Node.js library for hashing passwords using the bcrypt algorithm. It provides salt generation, hashing, and comparison with an adaptive cost factor that slows brute-force attacks.
Key Features
- Adaptive cost: Tunable work factor to resist hardware attacks
- Salt handling: Auto-generated or explicit salts
- Async and sync: Non-blocking and blocking APIs
- Safe compare: Constant-time comparison to prevent timing attacks
- Round inspection: Read cost factor from hashes
Errors
The following points are quoted verbatim from the official documentation (https://github.com/kelektiv/node.bcrypt.js). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- If you do not, you’ll likely see an error that starts with: gyp ERR! (https://github.com/kelektiv/node.bcrypt.js)
Security notes
Quoted from the official documentation (https://github.com/kelektiv/node.bcrypt.js); this is not a complete threat model.
- As should be the case with any security tool, anyone using this library should scrutinise it. (https://github.com/kelektiv/node.bcrypt.js)
- Here is a list of BCrypt-related security issues/concerns that have come up over the years. (https://github.com/kelektiv/node.bcrypt.js)
- If you end up using it for something else, we cannot guarantee the security of the comparator. (https://github.com/kelektiv/node.bcrypt.js)
FAQ
- What cost factor should I use?
- Choose the highest factor that keeps hashing under your latency budget, typically 10-12 for web apps. Increase it over time as hardware improves. Each increment roughly doubles the work factor.
- Should I use async or sync bcrypt methods?
- Prefer async methods (hash, compare) to avoid blocking the Node.js event loop during the intentionally slow hashing. Use sync variants only in scripts or startup code where blocking is acceptable.
- How is bcrypt different from argon2 or scrypt?
- bcrypt is battle-tested and widely supported but lacks memory hardness, making it vulnerable to GPU attacks. argon2 is the modern standard with memory and parallelism resistance, recommended for new systems where available.
Report a problem with this API docOpens a pre-filled issue on GitHub.