Never store plain text passwords. Use bcrypt for hashing.
Getting Started
What is Node.js?
Modules & NPM
Modules & NPM
Process & Environment
Process & Environment Variables
Caching & Performance
Redis Caching
GraphQL with Node.js
GraphQL Basics
Node.js
Intermediate
FREE
Password Hashing
Lesson 2 of 17
Intermediate
Interactive
Syntax
NODEJS
const bcrypt = require('bcrypt'); const hash = await bcrypt.hash("password123", 10); const match = await bcrypt.compare("password123", hash);
Password Hashing with bcrypt
NODE
const bcrypt = require("bcrypt"); async function hashPassword(password) { const salt = await bcrypt.genSalt(10); const hash = await bcrypt.hash(password, salt); console.log("Hash:", hash); return hash; } async function verifyPassword(password, hash) { const match = await bcrypt.compare(password, hash); console.log("Match:", match); return match; } // Usage hashPassword("mySecret123").then(hash => { verifyPassword("mySecret123", hash); verifyPassword("wrongPassword", hash); });