Skip to content

Commit

Permalink
generate admin user
Browse files Browse the repository at this point in the history
  • Loading branch information
zefir-git committed Jul 30, 2024
1 parent f439f55 commit 7b63305
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Album from "./resource/Album.js";
import Track from "./resource/Track.js";
import User from "./resource/User.js";
import Token from "./resource/Token.js";
import Password from "./Password.js";

const configArgIndex = process.argv.findIndex(arg => arg === "--config" || arg === "-c");
const customConfig = configArgIndex >= 0 && process.argv.length > configArgIndex + 1;
Expand Down Expand Up @@ -52,6 +53,22 @@ console.log("Reloading library... (this may take a while)");
const libLoad = await library.reload();
console.log(`Library loaded. Added ${libLoad.added} new track${libLoad.added === 1 ? "" : "s"}${libLoad.removed > 0 ? `, removed ${libLoad.removed} orphaned track${libLoad.removed === 1 ? "" : "s"}` : ""}.`);

// if no users in db, create default admin user
if (library.repositories.users.list({limit: 0, offset: 0}).total === 0) {
// using token secret generator just to get a good password
const password = Token.Secret.random().id;
library.repositories.users.save(new User(
User.ID.random(),
"admin",
new Set(Object.values(Token.Scope)), // all scopes
await Password.hash(password),
false
));
console.log("Generated a default administrator user:");
console.log("Username: admin");
console.log("Password: " + password);

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This logs sensitive data returned by
an access to password
as clear text.
}

process.on("SIGINT", async () => {
console.log("\rStopping...");
setTimeout(() => {
Expand Down

0 comments on commit 7b63305

Please sign in to comment.