Bcryptjs icon

Bcryptjs

Perform password hashing and verification using bcryptjs

Overview

This node provides password hashing and verification functionality using the bcryptjs library. It supports generating salts, hashing passwords with salts or rounds, comparing passwords against hashes, extracting salt or rounds from a hash, and testing if a password will be truncated by bcrypt.

Common scenarios where this node is useful include:

  • Securely storing user passwords by hashing them before saving to a database.
  • Verifying user login attempts by comparing entered passwords with stored hashes.
  • Generating salts for custom hashing workflows.
  • Inspecting existing bcrypt hashes to retrieve metadata like salt or number of rounds.

Practical examples:

  • Hash a new user's password before saving it.
  • Compare a login password with a stored hash to authenticate.
  • Generate a salt with a specific cost factor for use in other cryptographic operations.

Properties

Name Meaning
Operation The action to perform: "Compare Password", "Generate Salt", "Get Rounds", "Get Salt", "Hash Password", or "Test Truncation".
Rounds Number of processing rounds (cost factor) used when generating salt or hashing (default 10). Applicable for "genSalt" and "hash" operations.
Minor Version The minor version of bcrypt to use ("a" or "b"). Only applicable for "genSalt" operation.
Password The password string to hash, compare, or test truncation on. Used in "hash", "compare", and "truncates" operations.
Salt or Rounds Either a salt string or a number specifying rounds to use for hashing. Used in "hash" operation.
Hash The bcrypt hash string to compare against or extract information from. Used in "compare", "getRounds", and "getSalt" operations.
Options Collection of additional options:
- Output Field Name: The name of the field where the result will be saved (default "result").

Output

The node outputs an array of items, each containing a json object that includes all original input fields plus one additional field holding the result of the operation. The name of this result field defaults to "result" but can be customized via the "Output Field Name" option.

The content of the result field depends on the operation:

  • genSalt: A generated salt string.
  • hash: The resulting bcrypt hash string.
  • compare: A boolean indicating whether the password matches the hash.
  • getRounds: The number of rounds used in the given hash (integer).
  • getSalt: The salt portion extracted from the hash (string).
  • truncates: A boolean indicating if the password would be truncated by bcrypt.

No binary data output is produced by this node.

Dependencies

  • Requires the bcryptjs npm package bundled within the node.
  • No external API keys or services are needed.
  • No special environment variables or n8n credentials are required.

Troubleshooting

  • Common issues:

    • Providing an invalid salt or rounds value for hashing may cause errors.
    • Using an improperly formatted hash string for comparison or extraction will fail.
    • Forgetting to set the correct operation or mismatching parameters for the chosen operation.
  • Error messages:

    • Unknown operation: <operation>: Indicates an unsupported operation was selected; verify the operation parameter.
    • Bcryptjs <operation> operation failed: <message>: General failure during bcryptjs processing; check input values for correctness.
  • Resolutions:

    • Ensure the salt or rounds parameter is either a valid salt string or a numeric string convertible to an integer.
    • Confirm the hash strings are valid bcrypt hashes.
    • Double-check that the password parameter is provided when required.

Links and References

Discussion