如何在 node.js 中生成可在 url 中使用的密码重置令牌?
我只需要生成令牌的方法:
user.reset_password_token = ???;
user.reset_password_expire = expire_date;
编辑 - 这是解决方案:
user.reset_password_token = require('crypto').randomBytes(32).toString('hex');
我用它来生成我的身份验证令牌:
require('crypto').randomBytes(32, function(ex, buf) {
var token = buf.toString('hex');
});
Crypto Node.js v0.8.9 手册和文档 http://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)