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
+37
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "================================="
|
||||
echo "MinIO WebUI Password Generator"
|
||||
echo "================================="
|
||||
echo ""
|
||||
read -s -p "Enter password: " PASSWORD
|
||||
echo ""
|
||||
|
||||
if [ -z "$PASSWORD" ] || [ ${#PASSWORD} -lt 8 ]; then
|
||||
echo "Error: Password must be at least 8 characters long."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Generating password hash..."
|
||||
|
||||
# Use the backend container to generate the hash
|
||||
HASH=$(docker run --rm -it node:20-alpine sh -c "
|
||||
npm install bcrypt >/dev/null 2>&1 && \
|
||||
node -e \"
|
||||
const bcrypt = require('bcrypt');
|
||||
bcrypt.hash('$PASSWORD', 12).then(hash => console.log(hash));
|
||||
\"
|
||||
" | tr -d '\r')
|
||||
|
||||
echo ""
|
||||
echo "================================="
|
||||
echo "Password Hash Generated:"
|
||||
echo "================================="
|
||||
echo ""
|
||||
echo "$HASH"
|
||||
echo ""
|
||||
echo "Add this to your .env file:"
|
||||
echo "ADMIN_PASSWORD_HASH=$HASH"
|
||||
echo ""
|
||||
echo "================================="
|
||||
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();
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "================================="
|
||||
echo "MinIO WebUI Password Tester"
|
||||
echo "================================="
|
||||
echo ""
|
||||
|
||||
# Check if .env file exists
|
||||
if [ ! -f .env ]; then
|
||||
echo "Error: .env file not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the hash from .env
|
||||
HASH=$(grep ADMIN_PASSWORD_HASH .env | cut -d '=' -f2-)
|
||||
|
||||
if [ -z "$HASH" ]; then
|
||||
echo "Error: ADMIN_PASSWORD_HASH not found in .env"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Current hash in .env: ${HASH:0:20}..."
|
||||
echo ""
|
||||
|
||||
read -s -p "Enter password to test: " PASSWORD
|
||||
echo ""
|
||||
|
||||
# Test the password using Node.js in Docker
|
||||
docker run --rm node:20-alpine sh -c "
|
||||
npm install bcrypt >/dev/null 2>&1 && \
|
||||
node -e \"
|
||||
const bcrypt = require('bcrypt');
|
||||
const hash = '$HASH';
|
||||
const password = '$PASSWORD';
|
||||
bcrypt.compare(password, hash).then(result => {
|
||||
if (result) {
|
||||
console.log('\n✅ Password is CORRECT!');
|
||||
} else {
|
||||
console.log('\n❌ Password is INCORRECT!');
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('\n❌ Error:', err.message);
|
||||
});
|
||||
\"
|
||||
"
|
||||
|
||||
echo ""
|
||||
echo "================================="
|
||||
Reference in New Issue
Block a user