//방법 1. generate a salt and hash bcrypt.genSalt(saltRounds, function(err, salt) { bcrypt.hash(myPlaintextPassword, salt, function(err, hash) { // Store hash in your password DB. }); });
//방법 2. auto-gen a salt and hash bcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) { // Store hash in your password DB. });
비밀번호 비교시
1 2 3 4 5 6 7 8
//result 값이 true, false 로 로그인 프로세스를 처리하면 된다 // Load hash from your password DB. bcrypt.compare(myPlaintextPassword, hash, function(err, result) { // result == true }); bcrypt.compare(someOtherPlaintextPassword, hash, function(err, result) { // result == false });
async/await 로 사용
1 2 3 4 5 6 7 8 9 10 11
asyncfunctioncheckUser(username, password) { //... fetch user from a db etc.
const match = await bcrypt.compare(password, user.passwordHash);