Challenge - 5 Problems
bcrypt Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this bcrypt hash comparison?
Given the following Express code snippet using bcrypt, what will be the output logged to the console?
Express
import bcrypt from 'bcrypt'; const password = 'mypassword'; const hash = await bcrypt.hash(password, 10); const result = await bcrypt.compare('mypassword', hash); console.log(result);
Attempts:
2 left
💡 Hint
bcrypt.compare returns true if the plain text matches the hashed password.
✗ Incorrect
bcrypt.compare checks if the plain password matches the hashed one and returns true if they match.
❓ component_behavior
intermediateWhat happens if you use a wrong password in bcrypt.compare?
In an Express app, if you hash a password and then compare a different password using bcrypt.compare, what will be the result?
Express
const hash = await bcrypt.hash('correctpassword', 10); const result = await bcrypt.compare('wrongpassword', hash); console.log(result);
Attempts:
2 left
💡 Hint
bcrypt.compare returns false if passwords do not match.
✗ Incorrect
bcrypt.compare returns false when the plain password does not match the stored hash.
📝 Syntax
advancedWhich option correctly hashes a password with bcrypt in Express?
Choose the correct code snippet that hashes a password string using bcrypt with 12 salt rounds.
Attempts:
2 left
💡 Hint
bcrypt.hash returns a promise and needs await or then.
✗ Incorrect
bcrypt.hash is async and returns a promise, so you must await it or use then. Option B correctly awaits the promise.
🔧 Debug
advancedWhy does this bcrypt hash code throw an error?
Identify the cause of the error in this Express code snippet:
Express
import bcrypt from 'bcrypt'; const password = 'secret'; const hash = bcrypt.hash(password, 10); console.log(hash);
Attempts:
2 left
💡 Hint
Check if the code handles the asynchronous nature of bcrypt.hash.
✗ Incorrect
bcrypt.hash returns a promise. Without await or then(), the variable hash is a promise object, not the hashed string.
🧠 Conceptual
expertWhy is it important to use salt rounds in bcrypt hashing?
Select the best explanation for why bcrypt uses salt rounds when hashing passwords.
Attempts:
2 left
💡 Hint
Think about how salt rounds affect security and attack difficulty.
✗ Incorrect
Salt rounds increase the computational work needed to hash passwords, slowing down attackers trying many guesses.
