首页 > 解决方案 > 在 node.js 中验证 bcrypt

问题描述

我在登录时遇到密码验证问题。我得到一个“没有比较”的回复。我在哪里得到错误?

另外 user.password 未定义

function post(req, res) {
    User.find({ email: req.body.email,
    password:req.body.password })
        .then(user => {
            if (user.length < 1) {
                res.status(400).json({
                    message: "Mail dosent exists"
                });
            } else {
                bcrypt.genSalt(SALT_ROUNDS, function (error, salt) {
                    console.log("salt: " + "" + salt)
                    bcrypt.hash(req.body.password, salt, (error, hash) => {
                        bcrypt.compare(user.password, hash)
                            .then(result => {
                                res.status(200).send(result)
                                console.log("logged")
                            })
                            .catch(error => res.status(500).send(error));
                        console.log("no comparison")
                        console.log("hash:" + "" + hash)
                        console.log("hasło:" + "" + user.password)


                    });
                });
            }
        });
}

标签: node.jsmongodbbcrypt

解决方案


推荐阅读