Skip to content

Build your personal knowledge base with Trilium Notes

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

azivner4187ff36fbbc
diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.js
index 08ecc7987a..7267949e0a 100644
--- a/public/javascripts/note_tree.js
+++ b/public/javascripts/note_tree.js
@@ -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(' / ');
}
diff --git a/services/utils.js b/services/utils.js
index d0979dc12a..28d4acaf1a 100644
--- a/services/utils.js
+++ b/services/utils.js
@@ -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 = '';
-
- for (let i = length; i > 0; --i) {
- result += ALPHA_NUMERIC[Math.floor(Math.random() * ALPHA_NUMERIC.length)];
- }
+ const token = randomSecureToken(32);
- return result;
+ return token.substr(0, length);
}
function randomSecureToken(bytes = 32) {