crypto.randomBytes() instead of Math.random()
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
const crypto = require('crypto');
|
||||
|
||||
const accountController = {
|
||||
getCookie: (req, res) => {
|
||||
console.log("site loaded")
|
||||
console.log(req.cookies)
|
||||
var cookie = req.cookies.user;
|
||||
let cookie = req.cookies.user;
|
||||
if (!cookie) {
|
||||
var randomNumber=Math.random().toString();
|
||||
randomNumber=randomNumber.substring(2,randomNumber.length);
|
||||
//crypto.randomBytes() instead of Math.random() for cryptographically secure random numbers
|
||||
let randomBuffer = crypto.randomBytes(16); // 128bits of entropy
|
||||
let randomNumber = randomBuffer.toString('hex');
|
||||
let options = {
|
||||
maxAge: 86400000, // 1 day
|
||||
httpOnly: true
|
||||
|
Reference in New Issue
Block a user