From 870bb87b0858481cacf8c6a1d4bbd367917eaf58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 26 Apr 2017 13:17:03 -0400 Subject: [PATCH] always pass strings to bcrypt compare --- src/bcrypt.js | 2 +- src/password.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bcrypt.js b/src/bcrypt.js index 40a493e75d..8cce80372e 100644 --- a/src/bcrypt.js +++ b/src/bcrypt.js @@ -9,7 +9,7 @@ process.on('message', function (msg) { if (msg.type === 'hash') { hashPassword(msg.password, msg.rounds); } else if (msg.type === 'compare') { - bcrypt.compare(msg.password, msg.hash, done); + bcrypt.compare(String(msg.password || ''), String(msg.hash || ''), done); } }); diff --git a/src/password.js b/src/password.js index 816e357d12..5405941fff 100644 --- a/src/password.js +++ b/src/password.js @@ -9,6 +9,9 @@ }; module.compare = function (password, hash, callback) { + if (!hash || !password) { + return setImmediate(callback, null, false); + } forkChild({ type: 'compare', password: password, hash: hash }, callback); };