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

View File

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