0
0
Node.jsframework~10 mins

Password hashing with bcrypt in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import bcrypt in a Node.js file.

Node.js
const bcrypt = require('[1]');
Drag options to blanks, or click blank then click option'
Ahttp
Bcrypto
Cexpress
Dbcrypt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'crypto' instead of 'bcrypt' for password hashing.
Forgetting to install bcrypt before requiring it.
2fill in blank
medium

Complete the code to hash a password asynchronously with bcrypt.

Node.js
const hashedPassword = await bcrypt.[1](password, 10);
Drag options to blanks, or click blank then click option'
Acompare
BgenSalt
Chash
DhashSync
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'hashSync' which is synchronous instead of 'hash'.
Using 'compare' which is for checking passwords, not hashing.
3fill in blank
hard

Fix the error in the code to compare a plain password with a hashed password.

Node.js
const isMatch = await bcrypt.[1](plainPassword, hashedPassword);
Drag options to blanks, or click blank then click option'
Acompare
BgenSalt
Chash
DhashSync
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'hash' instead of 'compare' to check passwords.
Using synchronous methods in async code.
4fill in blank
hard

Fill both blanks to generate a salt and then hash a password using that salt.

Node.js
const salt = await bcrypt.[1](12);
const hashed = await bcrypt.[2](password, salt);
Drag options to blanks, or click blank then click option'
AgenSalt
Bhash
Ccompare
DhashSync
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'compare' instead of 'hash' for hashing.
Using synchronous methods in async code.
5fill in blank
hard

Fill all three blanks to create a function that hashes a password with 10 salt rounds and returns the hashed password.

Node.js
async function [1](password) {
  const salt = await bcrypt.[2](10);
  const hashed = await bcrypt.[3](password, salt);
  return hashed;
}
Drag options to blanks, or click blank then click option'
AhashPassword
BgenSalt
Chash
Dcompare
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'compare' inside the hashing function.
Not awaiting asynchronous bcrypt methods.