简体   繁体   English

没有提供回调给pbkdf2

[英]No callback provided to pbkdf2

I have this code, which works just fine on my development computer, but not on the server. 我有此代码,该代码在我的开发计算机上工作正常,但在服务器上工作不正常。

db.admin.verify([req.body.username]).then(function(data){
    if (data[0].length == 0){       //if there is no user with that username
        console.log("bad username");
        res.status(401).send('Incorrect username or password');
    }

    var creds = data[0][0];

    return myCrypt.pbkdf2(req.body.password, creds.salt).then(function(key){
        if (creds.password === key.toString('base64')){            //correct password
            console.log("correct pw");
            return db.admin.getUser([req.body.username])
        } else {
            console.log("bad pw");
            res.status(401).send('Incorrect password or username');
        }
    });
}).then(function(dbData){
    var user = dbData[0][0];
    var profile = {
        firstName: user.firstName,
        lastName: user.lastName,
        email: user.email,
        username: user.username,
        type: user.type,
        id: user.adminId
    };

    var token = jwt.sign(profile, 'secrets');

    res.json({token:token, user: profile});
}).catch(function(err){
    console.log('ERROR');
    console.log(err);
    throw err;
    res.status(500).json(err);
});

It is supposed to authenticate a user from a database by comparing hashes. 应该通过比较散列来从数据库对用户进行身份验证。 I am using node.js crypto library implementation of pbkdf2 wrapped in a Q promise. 我正在使用包装在Q promise中的pbkdf2的node.js加密库实现。

module.exports.pbkdf2 = function(password, salt) {

    var pbkdf2 = Q.denodeify(crypto.pbkdf2);

    return pbkdf2(password, salt, 4096, 512, 'sha512')
};

When I try running it on the server, it returns [Error: No callback provided to pbkdf2] , caught from the promises catch function. 当我尝试在服务器上运行它时,它返回[Error: No callback provided to pbkdf2] ,是从promises catch函数捕获的。

I've tried copying my entire project from the development to the server, just in case I didn't have any dependencies installed, but the error is still thrown. 我试图将我的整个项目从开发复制到服务器,以防万一我没有安装任何依赖项,但是仍然抛出错误。

Turns out that the pbkdf2 function signature broke between node 0.10 and 0.12, and it wasn't receiving the callback because I was passing the digest instead of a function callback. 原来pbkdf2函数签名在节点0.10和0.12之间中断,并且没有收到回调,因为我传递的是摘要而不是函数回调。 Updating nodejs to 0.12 fixed the issue. 将nodejs更新到0.12可以解决此问题。

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

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