0
0
Node.jsframework~20 mins

Password hashing with bcrypt in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
bcrypt Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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();
Atrue
Bfalse
Cundefined
DThrows an error
Attempts:
2 left
💡 Hint
bcrypt.compare returns true if the plain text matches the hash.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in bcrypt usage
Which option contains a syntax error when hashing a password with bcrypt?
Aconst hash = await bcrypt.hash(password, 10);
Bconst hash = await bcrypt.hash(password, '10');
Cconst hash = bcrypt.hash(password, 10);
Dconst hash = await bcrypt.hash(password 10);
Attempts:
2 left
💡 Hint
Check for missing commas and correct argument types.
component_behavior
advanced
2: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?
AHashing fails with an error
BHashing becomes faster but less secure
CHashing becomes slower but more secure
DHashing speed and security remain the same
Attempts:
2 left
💡 Hint
Salt rounds control the computational cost of hashing.
🔧 Debug
advanced
2: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);
Abcrypt.compare requires a callback, not await
BThe hash string was modified, so it no longer matches
CThe password 'secret' is incorrect
Dbcrypt.compare cannot handle synchronous hashes
Attempts:
2 left
💡 Hint
Check if the hash string is exactly the same as generated.
🧠 Conceptual
expert
2:00remaining
Why use bcrypt over simple hashing functions?
Why is bcrypt preferred for password hashing instead of simple hash functions like SHA-256?
Abcrypt is designed to be slow and includes salt to prevent rainbow table attacks
Bbcrypt produces shorter hashes than SHA-256
Cbcrypt hashes can be reversed to get the original password
Dbcrypt is faster and uses less memory than SHA-256
Attempts:
2 left
💡 Hint
Think about security features specific to password hashing.