mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
Merge pull request #866 from pano9000/refactor_session_secret
refactor(session_secret): use existing randomSecureToken function
This commit is contained in:
commit
a8f052071e
@ -1,9 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import crypto from "crypto";
|
|
||||||
import dataDir from "./data_dir.js";
|
import dataDir from "./data_dir.js";
|
||||||
import log from "./log.js";
|
import log from "./log.js";
|
||||||
|
import utils from "./utils.js"
|
||||||
|
|
||||||
const sessionSecretPath = `${dataDir.TRILIUM_DATA_DIR}/session_secret.txt`;
|
const sessionSecretPath = `${dataDir.TRILIUM_DATA_DIR}/session_secret.txt`;
|
||||||
|
|
||||||
@ -11,14 +11,8 @@ let sessionSecret: string;
|
|||||||
|
|
||||||
const ENCODING = "ascii";
|
const ENCODING = "ascii";
|
||||||
|
|
||||||
function randomValueHex(len: number) {
|
|
||||||
return crypto.randomBytes(Math.ceil(len / 2))
|
|
||||||
.toString('hex') // convert to hexadecimal format
|
|
||||||
.slice(0, len).toUpperCase(); // return required number of characters
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fs.existsSync(sessionSecretPath)) {
|
if (!fs.existsSync(sessionSecretPath)) {
|
||||||
sessionSecret = randomValueHex(64);
|
sessionSecret = utils.randomSecureToken(64).slice(0, 64);
|
||||||
|
|
||||||
log.info("Generated session secret");
|
log.info("Generated session secret");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user