J
J
jekanok2019-04-13 12:19:12
MySQL
jekanok, 2019-04-13 12:19:12

Authorization failed on node?

Here is the code where authorization on the site is processed, when I enter the correct password, then everything is OK, and if not, then the server crashes

app.post('/login', pasr, (req, res) => {
  if (!req.body) return res.sendStatus(400);
  connection.query(
    `SELECT password, email FROM users WHERE password = "${md5(req.body.password)}" AND email="${
      req.body.email
    }"`,
    (err, result) => {
      console.log(result);
      if (err === null) {
        if (result[0].password !== undefined) {
          // if (!result[0].password) {
          res.send('OK');
          // }
        } else {
          res.status(401).send('NO');
        }
      }
    }
  );
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Egorov, 2019-04-13
@SergeyEgorov

I can assume that when the wrong password is entered, result[0] will be undefined.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question