function checkPassword(username,password,callback){ var pwdHash; var queryStr = 'select * from user where username = ?'; db.query(queryStr,username,queryCallback); function queryCallback(err,result){ if(err) throw err; pwdHash = result['password_hash']; hash(password,hashCallback); } function hashCallback(data){ callback(data == pwdHash); } }