我目前正在做第一次忘记密码功能,这是到目前为止的代码。
为具有 JWT 令牌 URL 的用户发送电子邮件
router.post('/change-password', verifyAuth, resetPassword); 接收并确认 JWT 然后更改密码
router.post('/change-password/:token/:password', confirmResetPassword); 我目前正在考虑的过程在我发送给用户的电子邮件中
http://localhost:3000/change-passowrd?token=TOKEN_VALUE 但我不确定这是否是一个聪明的主意?如果更好,我也可以使用 cookie,知道吗?
可以将 JWT 令牌存储存储在 URL 中以用于重置密码功能。您必须使用电子邮件或任何其他安全通信服务发送此链接。
我实现了这个功能
https://yourapp.com/home/reset/${token}
const data = {
from: "[email protected]",
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 发送密码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句