Quiz Entry - updated: 2026.06.20
How do you securely register a new user with bcrypt?
Hash the submitted password with bcrypt.hash() and store only the resulting hash.
// Step 1: Hash the password
const hashedPassword = await bcrypt.hash(req.body.password, 10);
// Step 2: Store in database
db.collection('users').insertOne({
login: req.body.username,
hash: hashedPassword
});
// Step 3: Check for duplicate username (insertOne error)
The second parameter (10) is the cost factor - higher is more secure but slower.