feat: Add password generation and testing scripts
- Add generate-password.js for Node.js password hash generation - Add generate-password-docker.sh for Docker-based generation - Add test-password.sh to verify password against current hash These scripts help users generate correct bcrypt hashes for the ADMIN_PASSWORD_HASH environment variable. Usage: - Generate new hash: ./scripts/generate-password-docker.sh - Test current password: ./scripts/test-password.sh 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const bcrypt = require('bcrypt');
|
||||
const readline = require('readline');
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
terminal: true
|
||||
});
|
||||
|
||||
// Hide password input
|
||||
const askPassword = (query) => {
|
||||
return new Promise((resolve) => {
|
||||
const stdin = process.stdin;
|
||||
const stdout = process.stdout;
|
||||
|
||||
stdin.on('data', function onData(char) {
|
||||
char = char.toString();
|
||||
switch (char) {
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\u0004':
|
||||
stdin.removeListener('data', onData);
|
||||
stdout.write('\n');
|
||||
resolve(input);
|
||||
break;
|
||||
case '\u0003':
|
||||
process.exit();
|
||||
break;
|
||||
default:
|
||||
stdout.write('*');
|
||||
input += char;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
let input = '';
|
||||
stdout.write(query);
|
||||
});
|
||||
};
|
||||
|
||||
async function generatePasswordHash() {
|
||||
console.log('=================================');
|
||||
console.log('MinIO WebUI Password Generator');
|
||||
console.log('=================================\n');
|
||||
|
||||
const password = await new Promise((resolve) => {
|
||||
rl.question('Enter password: ', (answer) => {
|
||||
resolve(answer);
|
||||
});
|
||||
});
|
||||
|
||||
if (!password || password.length < 8) {
|
||||
console.error('\nError: Password must be at least 8 characters long.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('\nGenerating password hash...');
|
||||
|
||||
try {
|
||||
const hash = await bcrypt.hash(password, 12);
|
||||
|
||||
console.log('\n=================================');
|
||||
console.log('Password Hash Generated:');
|
||||
console.log('=================================\n');
|
||||
console.log(hash);
|
||||
console.log('\nAdd this to your .env file:');
|
||||
console.log(`ADMIN_PASSWORD_HASH=${hash}`);
|
||||
console.log('\n=================================');
|
||||
} catch (error) {
|
||||
console.error('Error generating hash:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
rl.close();
|
||||
}
|
||||
|
||||
generatePasswordHash();
|
||||
Reference in New Issue
Block a user