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 truncation behavior in bcrypt to ensure compatibility.

Practical example:

  • When a new user registers, use the "Hash Password" operation to generate a secure hash of their password.
  • During login, use the "Compare Password" operation to verify the entered password matches the stored hash.
  • Use "Test Truncation" to check if a given password exceeds bcrypt's maximum length and would be truncated.

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 will be saved. Default is "result".

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

Output

The node outputs an array with one item per input. Each output item contains a json object that includes all original input fields plus one additional field holding the operation result.

  • The name of the 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:
    • For "Test Truncation": a boolean indicating whether the password will be truncated by bcrypt.
    • For other operations (not requested here), it could be a generated salt string, hashed password string, comparison boolean, number of rounds, or extracted salt string.

No binary data is produced by this node.

Dependencies

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

Troubleshooting

  • Common issues:

    • Providing an empty or invalid password string may cause unexpected results or errors.
    • Using an unknown operation value will throw an error.
    • Incorrectly formatted salt or rounds parameter during hashing can cause failures.
  • Error messages:

    • "Unknown operation: <operation>": Indicates the selected operation is not supported. Verify the operation parameter.
    • "Bcryptjs <operation> operation failed: <message>": General failure during bcrypt processing. Check input values for correctness.

To resolve errors:

  • Ensure the password and other inputs are valid strings.
  • Confirm the operation is one of the supported options.
  • Use appropriate salt or rounds values when hashing.

Links and References

Discussion