Bcrypt Hash

Hash or compare passwords with bcrypt

Actions2

Overview

This node provides functionality to hash passwords or compare plain text passwords against existing bcrypt hashes. It is useful in scenarios where you need to securely store passwords by hashing them before saving, or verify user credentials by comparing a provided password with a stored hash.

Practical examples include:

  • Hashing a new user's password before saving it to a database.
  • Verifying a login attempt by comparing the entered password with the stored hashed password.

Properties

Name Meaning
Plain Text Password The password string to be hashed or compared.
Hash to Compare The existing bcrypt hash to compare the plain text password against (used only in Compare operation).

Additional property when hashing (not requested but present):
| Salt Rounds | Number of salt rounds to apply when hashing the password (default is 10). |

Output

The output JSON structure depends on the selected operation:

  • Hash operation: Outputs an object containing all original input fields plus a new field hashedPassword which holds the resulting bcrypt hash string.

    Example:

    {
      "hashedPassword": "$2b$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36r5Q6v7a0Fq8h9JH4xG6e."
    }
    
  • Compare operation: Outputs an object containing all original input fields plus a boolean field passwordMatches indicating whether the plain text password matches the given hash.

    Example:

    {
      "passwordMatches": true
    }
    

No binary data output is produced by this node.

Dependencies

  • Requires the bcrypt library for hashing and comparison operations.
  • No external API keys or services are needed.
  • No special environment variables or n8n configurations are required beyond standard node setup.

Troubleshooting

  • Empty Password Error: If the "Plain Text Password" input is empty, the node throws an error stating "Password cannot be empty." Ensure that this field is populated.
  • Empty Hash Error (Compare operation): If the "Hash to Compare" input is empty during a compare operation, the node throws "Hash to compare cannot be empty." Provide a valid bcrypt hash string.
  • Incorrect Hash Format: Providing an invalid or corrupted hash string may cause the bcrypt library to throw errors. Verify the hash format before comparison.
  • Performance Considerations: High salt rounds increase security but also processing time. The default of 10 is a balance; adjust according to your performance needs.

If the node is set to continue on failure, errors will be returned as part of the output JSON under an error field instead of stopping execution.

Links and References

Discussion