All checks were successful
Docker-Image veröffentlichen / publish (push) Successful in 1m44s
24 lines
1.0 KiB
JavaScript
24 lines
1.0 KiB
JavaScript
import { randomBytes, scryptSync } from 'node:crypto'
|
|
import { createInterface } from 'node:readline/promises'
|
|
import { Writable } from 'node:stream'
|
|
import { passwordOptions } from '../server/auth.js'
|
|
|
|
function readPassword() {
|
|
if (!process.stdin.isTTY) {
|
|
throw new Error('Bitte in einem interaktiven Terminal ausführen.')
|
|
}
|
|
const hidden = new Writable({ write(_chunk, _encoding, callback) { callback() } })
|
|
const reader = createInterface({ input: process.stdin, output: hidden, terminal: true })
|
|
reader.on('SIGINT', () => { process.stderr.write('\n'); process.exit(130) })
|
|
process.stderr.write('Admin-Passwort: ')
|
|
return reader.question('').finally(() => { reader.close(); process.stderr.write('\n') })
|
|
}
|
|
|
|
const password = await readPassword()
|
|
if (!password || password.length > 1024) {
|
|
throw new Error('Bitte ein Passwort mit 1 bis 1024 Zeichen eingeben.')
|
|
}
|
|
const salt = randomBytes(16)
|
|
const hash = scryptSync(password, salt, 64, passwordOptions)
|
|
console.log(`scrypt:${salt.toString('hex')}:${hash.toString('hex')}`)
|