weiter die Sache mit Auth
This commit is contained in:
61
scripts/generate-password.js
Executable file
61
scripts/generate-password.js
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Password Hash Generator
|
||||
*
|
||||
* Usage:
|
||||
* node scripts/generate-password.js [password]
|
||||
*
|
||||
* If no password is provided, you'll be prompted to enter one.
|
||||
*/
|
||||
|
||||
const bcrypt = require('bcryptjs');
|
||||
const readline = require('readline');
|
||||
|
||||
function generateHash(password) {
|
||||
const saltRounds = 10;
|
||||
const hash = bcrypt.hashSync(password, saltRounds);
|
||||
return hash;
|
||||
}
|
||||
|
||||
function promptPassword() {
|
||||
return new Promise((resolve) => {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
rl.question('Passwort eingeben: ', (password) => {
|
||||
rl.close();
|
||||
resolve(password);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
let password = process.argv[2];
|
||||
|
||||
if (!password) {
|
||||
password = await promptPassword();
|
||||
}
|
||||
|
||||
if (!password) {
|
||||
console.error('❌ Kein Passwort angegeben!');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('\n🔐 Generiere Passwort-Hash...\n');
|
||||
|
||||
const hash = generateHash(password);
|
||||
|
||||
console.log('✅ Hash generiert:');
|
||||
console.log('─'.repeat(80));
|
||||
console.log(hash);
|
||||
console.log('─'.repeat(80));
|
||||
console.log('\n📝 Verwende diesen Hash in der .env Datei:');
|
||||
console.log(`AUTH_USERS=username:${hash}`);
|
||||
console.log('\n💡 Beispiel für mehrere Benutzer:');
|
||||
console.log(`AUTH_USERS=admin:${hash},user2:$2a$10$...\n`);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Reference in New Issue
Block a user