0
0
Expressframework~10 mins

Password hashing with bcrypt in Express - 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 an Express app.

Express
const bcrypt = require('[1]');
Drag options to blanks, or click blank then click option'
Acors
Bexpress
Cbody-parser
Dbcrypt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of 'bcrypt' in require statement.
Forgetting to import bcrypt before using it.
2fill in blank
medium

Complete the code to hash a password asynchronously using bcrypt.

Express
const hashedPassword = await bcrypt.[1](password, 10);
Drag options to blanks, or click blank then click option'
Ahash
Bcompare
CgenSalt
Dverify
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'compare' instead of 'hash' to create a hash.
Not awaiting the asynchronous hash function.
3fill in blank
hard

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

Express
const isMatch = await bcrypt.[1](password, hashedPassword);
Drag options to blanks, or click blank then click option'
Ahash
BgenSalt
Ccompare
Dencrypt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'hash' instead of 'compare' to check passwords.
Passing arguments in wrong order.
4fill in blank
hard

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

Express
const salt = await bcrypt.[1](12);
const hashed = await bcrypt.[2](password, salt);
Drag options to blanks, or click blank then click option'
AgenSalt
Bcompare
Chash
Dencrypt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'compare' instead of 'genSalt' or 'hash'.
Not awaiting the asynchronous functions.
5fill in blank
hard

Fill all three blanks to create a function that hashes a password and returns the hashed value.

Express
async function [1](password) {
  const salt = await bcrypt.[2](10);
  const hash = await bcrypt.[3](password, salt);
  return hash;
}
Drag options to blanks, or click blank then click option'
AhashPassword
BgenSalt
Chash
Dcompare
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the function incorrectly.
Mixing up the order of salt generation and hashing.