Challenge - 5 Problems
bcrypt Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of bcrypt hash comparison
What will be the output of this Node.js code using bcrypt?
Node.js
import bcrypt from 'bcrypt'; async function test() { const password = 'mypassword'; const hash = await bcrypt.hash(password, 10); const result = await bcrypt.compare('mypassword', hash); console.log(result); } test();
Attempts:
2 left
💡 Hint
bcrypt.compare returns true if the plain text matches the hash.
✗ Incorrect
bcrypt.compare checks if the plain password matches the hashed password and returns true or false accordingly.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in bcrypt usage
Which option contains a syntax error when hashing a password with bcrypt?
Attempts:
2 left
💡 Hint
Check for missing commas and correct argument types.
✗ Incorrect
Option D is missing a comma between arguments, causing a syntax error.
❓ component_behavior
advanced2:00remaining
Behavior of bcrypt.hash with different salt rounds
What happens if you increase the salt rounds parameter in bcrypt.hash from 10 to 15?
Attempts:
2 left
💡 Hint
Salt rounds control the computational cost of hashing.
✗ Incorrect
Higher salt rounds increase the time to hash, making it harder to brute force, thus more secure but slower.
🔧 Debug
advanced2:00remaining
Why does bcrypt.compare always return false?
Given this code snippet, why does bcrypt.compare always return false?
const hash = bcrypt.hashSync('secret', 10);
const result = await bcrypt.compare('secret', hash + 'extra');
console.log(result);
Node.js
const hash = bcrypt.hashSync('secret', 10); const result = await bcrypt.compare('secret', hash + 'extra'); console.log(result);
Attempts:
2 left
💡 Hint
Check if the hash string is exactly the same as generated.
✗ Incorrect
Appending 'extra' to the hash changes it, so compare returns false.
🧠 Conceptual
expert2:00remaining
Why use bcrypt over simple hashing functions?
Why is bcrypt preferred for password hashing instead of simple hash functions like SHA-256?
Attempts:
2 left
💡 Hint
Think about security features specific to password hashing.
✗ Incorrect
bcrypt is slow and uses salt, making it resistant to brute force and rainbow table attacks, unlike fast hashes like SHA-256.