crypto.randomBytes() instead of Math.random()
This commit is contained in:
1 parent
8250e4f98f
commit
ba13626d46
2 files changed
+8
-4
No files matched your search
@@ -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