简体   繁体   中英

Adding an authentication challange logic to my website


I am developing a website using node.js as server.
I want to create a challenge based authentication logic.
The idea is that the client doesn't send the password to the server, but when he is trying to authenticate to the server, the server sends to the client a message to encrypt in the right way. The client sends the encrypted message and the server compare the sended message with the encrypted message. If the two messages are equal then the client is authenticated , otherwise he isn't. I want to create this logic in node.js. Does someone know how to do it? Is there a framework that could help me to do it?
Best regards,
Andrea

As your question you want to use some authentication . try this

Use JWT authentication.

npm install jsonwebtoken

some example code:

var jwt = require('jsonwebtoken');

// create token
jwt.sign(userDetails, 'secret_key', (err, token)=>{
    res.status(200).json({status:"success", resCode: 200, token: token }); //send this token to user
});

//validate token

jwt.verify(token, 'secret_key', (err, decoded) => {
  console.log(decoded) // bar
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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