강의

멘토링

커뮤니티

Inflearn Community Q&A

gcy's profile image
gcy

asked

Node and React series that you can learn by following - Basic lecture

Node React Basics Lecture #11 Login Function with Bcrypt (1)

어떻게 요청 비밀번호와 DB의 비밀번호가 같다고 확인할 수 있는지 모르겠어요

Written on

·

254

0

이 부분에서 compare의 첫 번째 인자와 두 번째 인자가 같을 시에 callback함수에 2번째 인자에 true 값을 전달 할 수 있는건 알겠는데, '어디에서 plainpassword를 암호화하는 것이기에' DB의 pw와 비교할 수 있는건지 모르겠어요 ㅠㅠ

bcrypt.compare(plainPasswordthis.password, (errisMatch=>

nodejsreact

Answer 2

0

plainpassword를 암호화하고 그것과 password를 비교하는 것은 compare함수 안에 있는 자체적인 기능입니다.

bcrypt.compare는 우리가 만든 함수가 아니라 라이브러리로서 다운받아 온 기능입니다.

0

John Ahn님의 프로필 이미지
John Ahn
Instructor

비밀번호를 암호화하는 것은 회원 가입할 때 암호화를 해서 데이터베이스에 암호화 된 값을 넣어줍니다 ~ 

bcrypt.genSalt(saltRounds, function (err, salt) {
if (err) return next(err)

bcrypt.hash(user.password, salt, function (err, hash) {
if (err) return next(err)
user.password = hash
next()
})
})

이 부분이 암호화 하는 부분입니다 ~ ! 

수고하세요 ~ ! 

gcy's profile image
gcy

asked

Ask a question