最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

SyntaxError:使用bcrypt模块的意外标识符

网站源码admin17浏览0评论

SyntaxError:使用bcrypt模块的意外标识符

SyntaxError:使用bcrypt模块的意外标识符

js,我创建了一个名为app.js的文件。我用bcrypt模块数据库编写的登录函数是MySQL。我几乎找不到哪个代码导致此错误。我下面有一个错误,如果您找到任何解决方案,请教我。

if (await bcryptpare(req.body.password, foundUser.password)) {
          ^^^^^^

SyntaxError: Unexpected identifier
    at ObjectpileFunction (vm.js:344:18)
    at wrapSafe (internal/modules/cjs/loader.js:1106:15)
    at Module._compile (internal/modules/cjs/loader.js:1140:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
[nodemon] app crashed - waiting for file changes before starting...

我检查了括号和方括号,但似乎没有错这是我的整个app.js文件

//jshint esversion:6

const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const app = express();
const mysql = require("mysql");
const bcrypt = require("bcrypt");

app.use(express.static("public"));
app.set("view engine", "ejs");
app.use(
  bodyParser.urlencoded({
    extended: true,
  })
);

app.get("/login", (req, res) => {
  res.render("login");
});

app.post("/login", async (req, res) => {
  connection.query(
    "SELECT * FROM user WHERE email=?",
    [req.body.useremail],
    (error, foundUser) => {
      if (foundUser.useremail == null) {
        res.status(400).send("Cannot find user");
      }
      try {
        if (await bcryptpare(req.body.password, foundUser.password)) {
          res.render("secrets");
        } else {
          res.send("email or password is wrong");
        }
      } catch {
        res.status(500).send();
      }
    },
  );
});

app.listen(3000, () => {
  console.log("Server is running on port 3000");
});
回答如下:

您是否尝试过更新或/和重新安装bcrypt版本?

发布评论

评论列表(0)

  1. 暂无评论