Bcryptjs icon

Bcryptjs

Perform password hashing and verification using bcryptjs

Overview

This node provides various operations related to password hashing and verification using the bcryptjs library. It supports generating salts, hashing passwords, 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.
  • Verifying user login attempts by comparing entered passwords with stored hashes.
  • Managing bcrypt parameters such as salt generation and cost factor inspection.
  • Testing password length constraints imposed by bcrypt truncation.

Practical example: You can use this node to hash a user's password during registration, then later compare the entered password during login to authenticate the user securely.

Properties

Name Meaning
Password The password string to process (hash, compare, or test truncation).
Options Collection of additional options:
- Output Field Name The name of the field in the output JSON where the result of the operation will be saved.

Note: The "Password" property is shown only for operations hash, compare, and truncates.

Output

The node outputs an array with one item per input item. Each output item contains a JSON object that includes all original input fields plus an additional field (default name "result" or as specified by the user) holding the result of the selected operation:

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

No binary data is produced by this node.

Dependencies

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

Troubleshooting

  • Unknown operation error: If an unsupported operation is selected, the node throws an error indicating the unknown operation. Ensure the operation parameter is set correctly.
  • Operation failure errors: Errors from bcryptjs (e.g., invalid salt format, malformed hash) will be caught and rethrown with a message specifying which operation failed. Verify inputs like password, salt, and hash values are valid.
  • Password truncation: The truncates operation helps detect if a password exceeds bcrypt's maximum length (usually 72 bytes). Use this to avoid unexpected authentication failures due to silent truncation.
  • Invalid rounds or salt: When generating salt or hashing, ensure the rounds parameter is a valid number and salt strings are properly formatted.

Links and References

Discussion