簡體   English   中英

Bcrypt.compare 不比較密碼

[英]Bcrypt.compare not comparing the passwords

我有一個 bcrypt.compare function,但它無法比較密碼,而是輸入的任何密碼都能夠返回正常狀態。 請參閱下面的代碼並幫助我。謝謝

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
        });
    }
);

我以前也有過這樣的。 您的密碼列或表有多長? Bcrypt 使用大於 60 個字符的字符串對密碼進行哈希處理。 是您在該范圍內的列嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM