diff --git a/scripts/generate-password-docker.sh b/scripts/generate-password-docker.sh new file mode 100755 index 0000000..1d8ff90 --- /dev/null +++ b/scripts/generate-password-docker.sh @@ -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 "=================================" \ No newline at end of file diff --git a/scripts/generate-password.js b/scripts/generate-password.js new file mode 100755 index 0000000..8eb019f --- /dev/null +++ b/scripts/generate-password.js @@ -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(); \ No newline at end of file diff --git a/scripts/test-password.sh b/scripts/test-password.sh new file mode 100755 index 0000000..965da6d --- /dev/null +++ b/scripts/test-password.sh @@ -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 "=================================" \ No newline at end of file