Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在节点js中传递object中的变量值_Node.js_Rest - Fatal编程技术网

Node.js 如何在节点js中传递object中的变量值

Node.js 如何在节点js中传递object中的变量值,node.js,rest,Node.js,Rest,我想将加密密码传递到对象中。所以当API调用时,密码将以加密的形式出现 app.post('/api/login', (req, res) => { const user = { id: 1, username: "Vinit", password: "12345" //Here I want to pass the encrypted password } jwt.sign(

我想将加密密码传递到对象中。所以当API调用时,密码将以加密的形式出现

app.post('/api/login', (req, res) => {

   const user = {
        id: 1,
        username: "Vinit",
        password: "12345" //Here I want to pass the encrypted password
    }

    jwt.sign({user: user}, 'secretkey', (err, token) => {
        res.json({
            token: token
        });
    });
});

如果尚未实现,则需要使用第三方库,如。然后你可以像这样生成散列密码

const bcrypt = require('bcryptjs');
bcrypt.genSalt(10, function(err, salt) {
    bcrypt.hash("NON_HASHED_PASSWORD", salt, function(err, hash) {
        console.log(hash) //<- Hashed password
    });
});
const bcrypt=require('bcryptjs');
bcrypt.genSalt(10,函数(错误,盐){
哈希(“非哈希密码”,salt,函数(err,hash){

console.log(hash)/试试-它有很多策略,包括
jwt
google auth
facebook
。等等。你的意思是像传递
req.body.password
?是的@David,但格式是加密的。请用bcrypt libary散列它。和是不同的东西。