From dcbe32a651295487799dec0bd12b768515723e36 Mon Sep 17 00:00:00 2001 From: Vietworm Date: Fri, 15 Apr 2016 12:14:12 +0700 Subject: [PATCH] Add function isHashed, valid BCrypt hash http://stackoverflow.com/questions/30877240/getting-error-the-string-not-a-valid-bcrypt-hash-was-thrown-throw-an-error --- bCrypt.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bCrypt.js b/bCrypt.js index 5246f47..0f9488f 100644 --- a/bCrypt.js +++ b/bCrypt.js @@ -701,6 +701,11 @@ function getRounds(encrypted) { return Number(encrypted.split("$")[2]); } +function isHashed(password) { + if (!password) return false; + return password.split('$').length == 4; +} + exports.genSaltSync = genSaltSync; exports.genSalt = genSalt; exports.hashSync = hashSync; @@ -708,3 +713,4 @@ exports.hash = hash; exports.compareSync = compareSync; exports.compare = compare; exports.getRounds = getRounds; +exports.isHashed = isHashed;