目前,我第一次忘记了密码功能,这是目前为止的代码。
为具有带有JWT令牌的URL的用户发送电子邮件
router.post('/change-password', verifyAuth, resetPassword);接收并确认JWT,然后更改密码。
router.post('/change-password/:token/:password', confirmResetPassword);我目前正在考虑的过程是在发送给用户的电子邮件中
http://localhost:3000/change-passowrd?token=TOKEN_VALUE但我不确定这是不是个聪明的主意?如果更好的话,我也可以用曲奇,知道吗?
发布于 2020-09-19 06:16:49
可以将JWT令牌存储在URL中,用于重置密码功能。您必须使用电子邮件或任何其他安全通信服务发送此链接。
我实现了这个特性
https://yourapp.com/home/reset/${token}
const data = {
from: "yourcompanymail@outlook.com",
to: user.email,
subject: "Please reset your password",
text: `Hello ${user.name},\n\nI heard that you lost your Teeny password. You can use the following link to reset your password: https://yourapp.com/home/reset/${token}
};
transporter.sendMail(data, function (error, info) {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});现在,如果用户单击此URL,则验证令牌并重定向或呈现更改密码页。但是不要通过URL发送密码。
https://stackoverflow.com/questions/63965511
复制相似问题