API Reference

@node-rs/bcrypt

Native bcrypt password hashing for Node.js via Rust bindings, with async hash, verify, and configurable cost factor.

Official Documentation ↗
CompatibilityThis documentation covers version v1.0. Check the official docs for the latest API surface.

Installation

npmnpm install @node-rs/bcrypt

Methods

@node-rs/bcrypt is native bcrypt password hashing for node.js via rust bindings, with async hash, verify, and configurable cost factor. This page documents the core methods, installation, and common usage patterns for the current stable release.

Installation

Install @node-rs/bcrypt with your preferred package manager using the command shown in the frontmatter. The package is published to the npm registry and ships with TypeScript types where applicable.

Core methods

The methods listed in the frontmatter cover the primary API surface. Each signature reflects the v1.0 release. Consult the official documentation linked in sourceUrl for advanced options, edge cases, and breaking changes between major versions.

Frequently asked questions

The faq section in the frontmatter answers the most common questions about @node-rs/bcrypt, including comparisons with alternatives, configuration tips, and runtime requirements. If your question is not covered, check the source URL for the full guide.

Errors

The official API reference declares the following error types:

Security

Official security statements captured from the package documentation:

  • bcrypt 最多使用 72 字节密码;该默认行为对哈希与校验一致 — “Bcrypt uses at most 72 password bytes. That default is unchanged for hashing and verification, including existing database hashes.” (source: https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/README.md, fetched 2026-11-08T17:53:10+08:00)
  • 可用 rejectLongPasswords: true 拒绝超过 72 字节的密码(按字节而非 JS 字符串长度判断) — “To reject longer passwords when creating a hash, explicitly set rejectLongPasswords: true. This checks bytes, not JavaScript string length, and accepts exactly 72 bytes. Verification has no length-policy option.” (source: https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/README.md, fetched 2026-11-08T17:53:10+08:00)

API reference evidence

Fetched from official sources on 2026-11-08T17:53:10+08:00 via WebFetch https://raw.githubusercontent.com/napi-rs/node-rs/main/packages/bcrypt/index.d.ts.

FAQ

What cost should I use?
12 is a common default; raise it so hashing takes about 250 ms on your hardware.
Is bcrypt better than argon2?
Argon2 is newer and memory-hard; bcrypt remains widely supported. Use argon2 for new systems.
Does it ship prebuilds?
Yes. node-rs packages include prebuilt binaries for Linux, macOS, and Windows.