53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Generate a bcrypt hash for ADMIN_PASSWORD_HASH
|
|
*
|
|
* Usage:
|
|
* node scripts/generate-hash.js "your-password-here"
|
|
*
|
|
* Or run interactively:
|
|
* node scripts/generate-hash.js
|
|
*/
|
|
|
|
const bcrypt = require('bcrypt');
|
|
const readline = require('readline');
|
|
|
|
const SALT_ROUNDS = 12;
|
|
|
|
async function generateHash(password) {
|
|
const hash = await bcrypt.hash(password, SALT_ROUNDS);
|
|
console.log('\n========================================');
|
|
console.log('Generated bcrypt hash:');
|
|
console.log('========================================');
|
|
console.log(hash);
|
|
console.log('========================================\n');
|
|
console.log('Set this as ADMIN_PASSWORD_HASH in your environment.');
|
|
console.log('For Portainer: paste the hash WITHOUT quotes.\n');
|
|
return hash;
|
|
}
|
|
|
|
async function main() {
|
|
const password = process.argv[2];
|
|
|
|
if (password) {
|
|
await generateHash(password);
|
|
} else {
|
|
// Interactive mode
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
});
|
|
|
|
rl.question('Enter password to hash: ', async (answer) => {
|
|
if (answer) {
|
|
await generateHash(answer);
|
|
} else {
|
|
console.log('No password provided.');
|
|
}
|
|
rl.close();
|
|
});
|
|
}
|
|
}
|
|
|
|
main().catch(console.error);
|