I'm trying to get "true" from hash compare. but a problem occurs when I write a username that does not exist in database.For example: if there is no "jack.33" as username, it is throwing mysql error and stopping the server. How can i block this error or create a solution? Here is the error:
throw err; // Rethrow non-MySQL errors
^
TypeError: Cannot read property 'password' of undefined
app.post("/login", function(request, response) {
var username = request.body.username;
var pass = request.body.pass;
con.query("select password from user where username = " + "\"" + username + "\"",function (err, result) {
if(err) throw err;
var passer = result[0].password;
bcrypt.compare(pass, passer, function (err, res) {
console.log(res);
if (res === true) {
response.send("success")
}else{
response.send("nop")
}
});
});
});
resultarray actually has stuff in it. The query can succeed but produce zero rows.