bcrypt

romini·2024년 5월 9일

express modules

목록 보기
2/5

사용목적

  • 비밀번호를 암호화해서 DB에 넣는 목적으로 사용
  • 단방향 해쉬 알고리즘으로 복호화가 불가능 하다.
  • 비밀번호 분실 시 비밀번호 재설정이나 임시 비밀번호를 발급하는 이유..

설치하기

npm install bcrypt

사용하기

import dotenv from 'dotent';
import bycrypt from 'bcrypt';

const password = "12345";

// env파일을 사용하기 위한 라이브러리
dotenv.config();

// 암호화를 위한 key
const salt = Number(process.env.PASSWORD_SALT);
// 해쉬 비밀번호 생성
const hashPassword = await bycrypt.hash(password, salt);

console.log(hashPassword);

// 두 패스워드 일치하는지 비교
const isCorrect = await bycrypt.compare(password, hashPassword); 

Key Generator : https://randomkeygen.com/

0개의 댓글