설치하기
yarn add bcrpyt
yarn add -D @types/bcrypt
실행하기
ts-node src/bcryptEx.ts
Bcrypt로 비밀번호 암호화 하기 (src/bcryptEx.ts)
import bcrypt from "bcrypt";
async function hashPassword(password: string) {
const hashedPassword = await bcrypt.hash(password, 10);
return hashedPassword;
}
async function comparePassword(password: string) {
const isMatched = await bcrypt.compare(
password,
"$2b$10$SOomUbeDdeaKHobF40/ADeVAcSTZE/5LHCKtJJ8cnEHb7XfX9Yx0y"
);
📍console.log(isMatched);
}
async function main() {
const hashedPassword = await hashPassword("123123");
📍console.log(hashedPassword);
comparePassword("123123");
}
main();
console창
📍$2b$10$lOq.PzIsXvFXR/RBCfAinesNixCnlScu1qDfOH39dgVWS5PwCmeqa
📍true