generating all IDs with secure method (important now since it's used as salt for encryption)

This commit is contained in:
azivner 2017-12-07 22:57:39 -05:00
parent b81f1ed93a
commit 4187ff36fb
2 changed files with 3 additions and 14 deletions

View File

@ -304,9 +304,6 @@ const noteTree = (function() {
let parentNoteId = 'root';
console.log('notePath: ' + notePath);
console.log('notePath chunks: ', notePath.split('/'));
for (const noteId of notePath.split('/')) {
console.log('noteId: ' + noteId);
@ -315,8 +312,6 @@ const noteTree = (function() {
parentNoteId = noteId;
}
console.log("Title path:", titlePath.join(' / '));
return titlePath.join(' / ');
}

View File

@ -3,7 +3,7 @@
const crypto = require('crypto');
function newNoteId() {
return randomString(8);
return randomString(12);
}
function newNoteTreeId() {
@ -14,16 +14,10 @@ function newNoteHistoryId() {
return randomString(12);
}
const ALPHA_NUMERIC = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
function randomString(length) {
let result = '';
const token = randomSecureToken(32);
for (let i = length; i > 0; --i) {
result += ALPHA_NUMERIC[Math.floor(Math.random() * ALPHA_NUMERIC.length)];
}
return result;
return token.substr(0, length);
}
function randomSecureToken(bytes = 32) {