简体   繁体   English

Bcrypt.compare 不比较密码

[英]Bcrypt.compare not comparing the passwords

I have a bcrypt.compare function, but it couldn't compare the passwords rather any password entered was able to return status ok.我有一个 bcrypt.compare function,但它无法比较密码,而是输入的任何密码都能够返回正常状态。 See the code below and help me out.Thanks请参阅下面的代码并帮助我。谢谢

bcrypt.compare(req.body.password, users.password).then(
    (valid) => { 
        if (!valid) {
            return res.status(401).json({
                error: new Error('Incorrect password!')
            });
        }
        const token = jwt.sign(
            { userId: users._id },
            'RANDOM_TOKEN_SECRET',
            { expiresIn: '24h' }
        );
        res.status(200).json({
            userId: users._id,
            token: 'token'
        });
    }
).catch(
    (error) => {
        res.status(500).json({
            error: error
        });
    }
);

I once had some like this before.我以前也有过这样的。 How long is your password column or table?您的密码列或表有多长? Bcrypt hashes the password with an string greater than 60 chars. Bcrypt 使用大于 60 个字符的字符串对密码进行哈希处理。 Is it your column on that range?是您在该范围内的列吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM