encryption

This commit is contained in:
2025-10-02 16:25:31 -04:00
parent 2a6228629a
commit dfa857c131
4 changed files with 25 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import Database from 'better-sqlite3'
import { join } from 'path'
import bcrypt from 'bcrypt'
let db: Database.Database | null = null
@@ -52,15 +53,17 @@ export function getDatabase() {
)
`)
// Insert default admin user from environment variables
// In production, this should be hashed properly
// Insert default admin user from environment variables with hashed password
const config = useRuntimeConfig()
const adminUsername = config.adminUsername
const adminPassword = config.adminPassword
const userExists = db.prepare('SELECT COUNT(*) as count FROM users WHERE username = ?').get(adminUsername) as { count: number }
if (userExists.count === 0) {
db.prepare('INSERT INTO users (username, password) VALUES (?, ?)').run(adminUsername, adminPassword)
// Hash the password before storing
const saltRounds = 10
const hashedPassword = bcrypt.hashSync(adminPassword, saltRounds)
db.prepare('INSERT INTO users (username, password) VALUES (?, ?)').run(adminUsername, hashedPassword)
}
}