서버사이드/NodeJS

Nestjs 따라잡기 8

Dohoon 2024. 8. 24. 23:21

비밀번호 암호화 - bcrypt 

  • 2가지 방식의 최종 결과는 동일
  • generate a salt and hash on separate function calls - 별도의 함수 호출에서 솔트와 해시 생성
  • auto-gen a salt and hash - 솔트와 해시 자동 생성

사용법

  • 설치 : npm install --save bcrypt @types/bcrypt
  • import * as bcrypt from 'bcrypt'
  • user.password =await bcrypt.hash(user.password,10);
  • await bcrypt.compare(ipw,opw)