//First install required package:
npm i bcrypt
//import bcrypt
import * as bcrypt from 'bcrypt';
//hashing the password using the hash function
const recievedPassword = 'password';
const hashedPassword = await bcrypt.hash(recievedPassword, await bcrypt.genSalt());
//To compare/check a password, use the compare function:
const isMatch = await bcrypt.compare(recievedPassword, hashedPassword);
console.log('passwords: ', isMatch);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter