Generate reset password in node.js

How do I generate a reset password in node.js that can be used in a URL?

I only need a way to generate a token:

user.reset_password_token = ???; user.reset_password_expire = expire_date; 

Edit - here is the solution:

 user.reset_password_token = require('crypto').randomBytes(32).toString('hex'); 
+6
source share
2 answers

I use this to generate my authentication token:

 require('crypto').randomBytes(32, function(ex, buf) { var token = buf.toString('hex'); }); 

Crypto Node.js v0.8.9 Guide and Documentation

+13
source
 function customToken() { var buffreValue = new Buffer(64); for (var i = 0; i < buffreValue.length; i++) { buffreValue[i] = Math.floor(Math.random() * 256); } var token = buffreValue.toString('base64'); return token; } var getToken = customToken() 
0
source

Source: https://habr.com/ru/post/926185/


All Articles