0
0
Expressframework~20 mins

Password hashing with bcrypt in Express - 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
What 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);
Aundefined
Bfalse
Ctrue
DThrows an error
Attempts:
2 left
💡 Hint
bcrypt.compare returns true if the plain text matches the hashed password.
component_behavior
intermediate
2:00remaining
What 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);
Afalse
BThrows a TypeError
Ctrue
Dundefined
Attempts:
2 left
💡 Hint
bcrypt.compare returns false if passwords do not match.
📝 Syntax
advanced
2:00remaining
Which 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.
Aconst hash = bcrypt.hash('pass123', 12);
Bconst hash = await bcrypt.hash('pass123', 12);
Cconst hash = bcrypt.hashSync('pass123', 12);
Dconst hash = bcrypt.hash('pass123', '12');
Attempts:
2 left
💡 Hint
bcrypt.hash returns a promise and needs await or then.
🔧 Debug
advanced
2:00remaining
Why 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);
Abcrypt.hash returns a promise and must be awaited or handled with then()
Bbcrypt.hash requires a callback function as the third argument
CThe salt rounds must be a string, not a number
Dbcrypt.hash cannot hash strings shorter than 8 characters
Attempts:
2 left
💡 Hint
Check if the code handles the asynchronous nature of bcrypt.hash.
🧠 Conceptual
expert
2:00remaining
Why is it important to use salt rounds in bcrypt hashing?
Select the best explanation for why bcrypt uses salt rounds when hashing passwords.
ASalt rounds are used to encrypt the password instead of hashing it
BSalt rounds reduce the size of the hashed password for storage efficiency
CSalt rounds allow bcrypt to generate multiple hashes for the same password instantly
DSalt rounds increase the time needed to hash, making brute-force attacks slower
Attempts:
2 left
💡 Hint
Think about how salt rounds affect security and attack difficulty.