From 448d774b0df72616d9aa07e3c6512fe622c4e7a2 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 27 Mar 2013 15:02:43 -0500 Subject: [PATCH] Wrap bcrypt in a try-catch --- auth.js | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/auth.js b/auth.js index 1910ea50..8ec8d080 100644 --- a/auth.js +++ b/auth.js @@ -77,28 +77,34 @@ exports.login = function(name, pw) { var results = db.querySync(query); var rows = results.fetchAllSync(); if(rows.length > 0) { - if(bcrypt.compareSync(pw, rows[0].pw)) { - db.closeSync(); - return rows[0]; - } - else { - // Check if the sha256 is in the database - // If so, migrate to bcrypt - var sha256 = hashlib.sha256(pw); - if(sha256 == rows[0].pw) { - var newhash = bcrypt.hashSync(pw, 10); - var query = "UPDATE registrations SET pw='{1}' WHERE uname='{2}'" - .replace(/\{1\}/, newhash) - .replace(/\{2\}/, name); - var results = db.querySync(query); + try { + if(bcrypt.compareSync(pw, rows[0].pw)) { db.closeSync(); - if(!results) { - Logger.errlog.log("Failed to migrate password! user=" + name); - return false; - } return rows[0]; } - return false; + else { + // Check if the sha256 is in the database + // If so, migrate to bcrypt + var sha256 = hashlib.sha256(pw); + if(sha256 == rows[0].pw) { + var newhash = bcrypt.hashSync(pw, 10); + var query = "UPDATE registrations SET pw='{1}' WHERE uname='{2}'" + .replace(/\{1\}/, newhash) + .replace(/\{2\}/, name); + var results = db.querySync(query); + db.closeSync(); + if(!results) { + Logger.errlog.log("Failed to migrate password! user=" + name); + return false; + } + return rows[0]; + } + return false; + } + } + catch(e) { + Logger.errlog.log("Auth.login fail"); + Logger.errlog.log(e); } } return false;