feat: Add password hash generation scripts
- Add simple hash-password script for quick hash generation - Add interactive generate-password script with hidden input - Include password validation and requirements display - Add npm scripts for easy execution - Create comprehensive PASSWORD_GENERATION.md guide - Use existing bcrypt infrastructure with 12 salt rounds Usage: npm run hash-password YourPassword123\! npm run generate-password (interactive) This solves the issue where bcrypt command line tools don't work properly for generating compatible hashes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const bcrypt = require('bcrypt');
|
||||
const readline = require('readline');
|
||||
|
||||
// Colors for console output
|
||||
const colors = {
|
||||
reset: '\x1b[0m',
|
||||
green: '\x1b[32m',
|
||||
yellow: '\x1b[33m',
|
||||
blue: '\x1b[36m',
|
||||
red: '\x1b[31m'
|
||||
};
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
// Hide password input
|
||||
rl._writeToOutput = function _writeToOutput(stringToWrite) {
|
||||
if (rl.stdoutMuted)
|
||||
rl.output.write("*");
|
||||
else
|
||||
rl.output.write(stringToWrite);
|
||||
};
|
||||
|
||||
console.log(`${colors.blue}=== MinIO WebUI Password Hash Generator ===${colors.reset}\n`);
|
||||
|
||||
rl.question('Enter the password you want to hash: ', async (password) => {
|
||||
rl.stdoutMuted = true;
|
||||
|
||||
if (!password || password.length === 0) {
|
||||
console.log(`\n${colors.red}Error: Password cannot be empty${colors.reset}`);
|
||||
rl.close();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`\n${colors.yellow}Generating hash...${colors.reset}`);
|
||||
|
||||
// Use the same salt rounds as in the application (default is 10)
|
||||
const saltRounds = 12;
|
||||
const hash = await bcrypt.hash(password, saltRounds);
|
||||
|
||||
console.log(`\n${colors.green}✓ Password hash generated successfully!${colors.reset}\n`);
|
||||
console.log('Add this to your .env file:');
|
||||
console.log(`${colors.yellow}ADMIN_PASSWORD_HASH=${hash}${colors.reset}`);
|
||||
|
||||
// Verify the hash works
|
||||
const verifyResult = await bcrypt.compare(password, hash);
|
||||
if (verifyResult) {
|
||||
console.log(`\n${colors.green}✓ Hash verification successful${colors.reset}`);
|
||||
} else {
|
||||
console.log(`\n${colors.red}✗ Hash verification failed${colors.reset}`);
|
||||
}
|
||||
|
||||
console.log('\nPassword requirements:');
|
||||
console.log('- Minimum 8 characters');
|
||||
console.log('- At least one uppercase letter');
|
||||
console.log('- At least one lowercase letter');
|
||||
console.log('- At least one number');
|
||||
console.log('- At least one special character');
|
||||
|
||||
} catch (error) {
|
||||
console.error(`\n${colors.red}Error generating hash:${colors.reset}`, error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
rl.close();
|
||||
});
|
||||
|
||||
rl.on('close', () => {
|
||||
console.log(`\n${colors.blue}Done!${colors.reset}`);
|
||||
process.exit(0);
|
||||
});
|
||||
Reference in New Issue
Block a user