0
0
Expressframework~30 mins

Password hashing with bcrypt in Express - Mini Project: Build & Apply

Choose your learning style9 modes available
Password hashing with bcrypt in Express
📖 Scenario: You are building a simple Express server that needs to securely store user passwords. Instead of saving plain text passwords, you will use bcrypt to hash them before saving.
🎯 Goal: Create an Express app that hashes a user password using bcrypt before saving it.
📋 What You'll Learn
Create a variable with a plain text password string
Add a variable for bcrypt salt rounds
Use bcrypt to hash the password with the salt rounds
Export the hashed password or use it in the app
💡 Why This Matters
🌍 Real World
Password hashing is essential for securely storing user passwords in web applications to protect user data.
💼 Career
Understanding bcrypt and password hashing is a key skill for backend developers working on authentication and security.
Progress0 / 4 steps
1
Create a plain text password variable
Create a variable called plainPassword and set it to the string "mysecret123".
Express
Need a hint?

Use const plainPassword = "mysecret123"; to create the variable.

2
Add bcrypt salt rounds variable
Create a variable called saltRounds and set it to the number 10.
Express
Need a hint?

Use const saltRounds = 10; to set the salt rounds.

3
Hash the password using bcrypt
Import bcrypt at the top with import bcrypt from 'bcrypt';. Then create an async function called hashPassword that uses await bcrypt.hash(plainPassword, saltRounds) to hash the password and returns the hashed password.
Express
Need a hint?

Use async function hashPassword() { const hashed = await bcrypt.hash(plainPassword, saltRounds); return hashed; }

4
Export the hashed password function
Add export default hashPassword; at the end of the file to export the hashPassword function.
Express
Need a hint?

Use export default hashPassword; to export the function.