This commit is contained in:
ghostersk
2025-07-16 15:39:28 +01:00
commit cb13605d85
17 changed files with 4014 additions and 0 deletions

664
web/password.html Normal file
View File

@@ -0,0 +1,664 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Generator - HeaderAnalyzer</title>
<link rel="stylesheet" href="/static/style.css">
<style>
.password-generator {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.password-output {
background: #1a1a1a;
border: 2px solid #333;
border-radius: 8px;
padding: 20px;
margin: 20px 0;
font-family: 'Courier New', monospace;
font-size: 18px;
word-break: break-all;
position: relative;
}
.password-text {
color: #00ff88;
font-weight: bold;
margin-bottom: 10px;
}
.copy-btn {
background: #007acc;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.copy-btn:hover {
background: #005999;
}
.copy-btn.copied {
background: #00aa44;
}
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
margin: 20px 0;
}
.control-group {
background: #1a1a1a;
border: 1px solid #333;
border-radius: 8px;
padding: 20px;
}
.control-group h3 {
margin-top: 0;
color: #00ff88;
border-bottom: 1px solid #333;
padding-bottom: 10px;
}
.form-row {
margin: 15px 0;
display: flex;
align-items: center;
gap: 10px;
}
.form-row label {
flex: 1;
color: #ccc;
}
.form-row input[type="number"],
.form-row input[type="text"],
.form-row select {
background: #2a2a2a;
border: 1px solid #444;
color: #fff;
padding: 8px;
border-radius: 4px;
width: 120px;
}
.form-row input[type="text"] {
width: 200px;
}
.form-row input[type="checkbox"] {
width: auto;
}
.generate-btn {
background: #00aa44;
color: white;
border: none;
padding: 15px 30px;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
width: 100%;
margin: 20px 0;
}
.generate-btn:hover {
background: #008833;
}
.tab-buttons {
display: flex;
margin-bottom: 20px;
border-radius: 8px;
overflow: hidden;
border: 1px solid #333;
}
.tab-btn {
flex: 1;
background: #2a2a2a;
color: #ccc;
border: none;
padding: 15px;
cursor: pointer;
font-size: 16px;
}
.tab-btn.active {
background: #007acc;
color: white;
}
.tab-btn:hover:not(.active) {
background: #333;
}
.passphrase-controls {
display: none;
}
.passphrase-controls.active {
display: block;
}
.url-share {
background: #2a2a2a;
border: 1px solid #444;
border-radius: 8px;
padding: 15px;
margin: 20px 0;
}
.url-share input {
background: #1a1a1a;
border: 1px solid #333;
color: #ccc;
padding: 8px;
border-radius: 4px;
width: 100%;
font-size: 12px;
}
@media (max-width: 768px) {
.controls {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<nav>
<div class="nav-container">
<div class="nav-links">
<a href="/">Email Analysis</a>
<a href="/dns">DNS Tools</a>
<a href="/password" class="active">Password Generator</a>
</div>
</div>
</nav>
<div class="container password-generator">
<h1>🔐 Password Generator</h1>
<div class="tab-buttons">
<button class="tab-btn" id="randomTab">Random Password</button>
<button class="tab-btn active" id="passphraseTab">Passphrase</button>
</div>
<div class="password-output">
<div class="password-text" id="passwordDisplay">Click "Generate Password" to create a secure password</div>
<button class="copy-btn" id="copyBtn" onclick="copyPassword()" style="display: none;">Copy to Clipboard</button>
</div>
<button class="generate-btn" onclick="generatePassword()">🎲 Generate Password</button>
<div class="controls">
<div class="control-group">
<h3>🔧 Basic Settings</h3>
<div class="form-row">
<label for="length">Password Length:</label>
<input type="number" id="length" min="4" max="128" value="12">
</div>
<div class="form-row">
<label for="includeUpper">Include Uppercase (A-Z):</label>
<input type="checkbox" id="includeUpper" checked>
</div>
<div class="form-row">
<label for="includeLower">Include Lowercase (a-z):</label>
<input type="checkbox" id="includeLower" checked>
</div>
<div class="form-row">
<label for="numberCount">Number of Digits:</label>
<input type="number" id="numberCount" min="0" max="20" value="1">
</div>
<div class="form-row">
<label for="specialChars">Special Characters:</label>
<input type="text" id="specialChars" value="!@#$%^&*-_=+">
</div>
<div class="form-row">
<label for="noConsecutive">No consecutive identical characters:</label>
<input type="checkbox" id="noConsecutive">
</div>
</div>
<div class="control-group">
<h3>🎯 Advanced Settings</h3>
<div class="passphrase-controls active" id="passphraseControls">
<div class="form-row">
<label for="wordCount">Number of Words:</label>
<input type="number" id="wordCount" min="2" max="10" value="3">
</div>
<div class="form-row">
<label for="passphraseUseNumbers">Include Numbers:</label>
<input type="checkbox" id="passphraseUseNumbers" checked>
</div>
<div class="form-row">
<label for="passphraseUseSpecial">Include Special Characters:</label>
<input type="checkbox" id="passphraseUseSpecial" checked>
</div>
<div class="form-row">
<label for="numberPosition">Number Position:</label>
<select id="numberPosition">
<option value="end">At End</option>
<option value="start">At Start</option>
<option value="each">After Each Word</option>
</select>
</div>
</div>
<div class="form-row">
<label>Strength Indicator:</label>
<div id="strengthIndicator" style="color: #999;">Generate a password to see strength</div>
</div>
<div class="form-row">
<label>Word List Status:</label>
<div id="wordListStatus" style="color: #999; font-size: 12px;">Loading...</div>
</div>
<div class="form-row">
<label for="enableHistory">Save Password History (7 days):</label>
<input type="checkbox" id="enableHistory">
</div>
</div>
</div>
<div id="historySection" style="display: none; margin-top: 20px;">
<div class="control-group" style="max-width: 100%;">
<h3>📜 Password History</h3>
<div style="max-height: 300px; overflow-y: auto;">
<table id="historyTable" style="width: 100%; border-collapse: collapse;">
<thead>
<tr style="background: #2a2a2a;">
<th style="padding: 8px; border: 1px solid #444; text-align: left; color: #ccc;">Timestamp</th>
<th style="padding: 8px; border: 1px solid #444; text-align: left; color: #ccc;">Password</th>
<th style="padding: 8px; border: 1px solid #444; text-align: left; color: #ccc;">Type</th>
<th style="padding: 8px; border: 1px solid #444; text-align: left; color: #ccc;">Action</th>
</tr>
</thead>
<tbody id="historyBody">
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
let currentMode = 'passphrase'; // Default to passphrase
// Load settings from cookies and URL parameters
window.addEventListener('load', function() {
loadSettings();
updateShareUrl();
loadWordListInfo();
// Auto-generate if URL has parameters
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.toString()) {
generatePassword();
}
});
async function loadWordListInfo() {
try {
const response = await fetch('/api/password/info');
if (response.ok) {
const info = await response.json();
document.getElementById('wordListStatus').innerHTML =
`${info.wordCount} words from ${info.source}<br><small>Last updated: ${info.lastUpdate}</small>`;
} else {
document.getElementById('wordListStatus').textContent = 'Failed to load word list info';
}
} catch (error) {
document.getElementById('wordListStatus').textContent = 'Error loading word list info';
}
}
function switchTab(mode) {
currentMode = mode;
document.getElementById('randomTab').classList.toggle('active', mode === 'random');
document.getElementById('passphraseTab').classList.toggle('active', mode === 'passphrase');
document.getElementById('passphraseControls').classList.toggle('active', mode === 'passphrase');
saveSettings();
updateShareUrl();
}
document.getElementById('randomTab').addEventListener('click', () => switchTab('random'));
document.getElementById('passphraseTab').addEventListener('click', () => switchTab('passphrase'));
function getConfig() {
return {
length: parseInt(document.getElementById('length').value),
includeUpper: document.getElementById('includeUpper').checked,
includeLower: document.getElementById('includeLower').checked,
numberCount: parseInt(document.getElementById('numberCount').value),
specialChars: document.getElementById('specialChars').value,
noConsecutive: document.getElementById('noConsecutive').checked,
usePassphrase: currentMode === 'passphrase',
wordCount: parseInt(document.getElementById('wordCount').value),
numberPosition: document.getElementById('numberPosition').value,
passphraseUseNumbers: document.getElementById('passphraseUseNumbers').checked,
passphraseUseSpecial: document.getElementById('passphraseUseSpecial').checked,
enableHistory: document.getElementById('enableHistory').checked
};
}
function setConfig(config) {
document.getElementById('length').value = config.length || 12;
document.getElementById('includeUpper').checked = config.includeUpper !== false;
document.getElementById('includeLower').checked = config.includeLower !== false;
document.getElementById('numberCount').value = config.numberCount || 1;
document.getElementById('specialChars').value = config.specialChars || '!@#$%^&*-_=+';
document.getElementById('noConsecutive').checked = config.noConsecutive || false;
document.getElementById('wordCount').value = config.wordCount || 3;
document.getElementById('numberPosition').value = config.numberPosition || 'end';
document.getElementById('passphraseUseNumbers').checked = config.passphraseUseNumbers !== false;
document.getElementById('passphraseUseSpecial').checked = config.passphraseUseSpecial !== false;
document.getElementById('enableHistory').checked = config.enableHistory || false;
if (config.usePassphrase !== false) { // Default to passphrase
switchTab('passphrase');
} else {
switchTab('random');
}
}
function saveSettings() {
const config = getConfig();
config.mode = currentMode;
document.cookie = 'passwordGenSettings=' + encodeURIComponent(JSON.stringify(config)) + '; max-age=31536000; path=/';
}
function loadSettings() {
// First try URL parameters
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.toString()) {
const config = {};
for (const [key, value] of urlParams) {
if (key === 'includeUpper' || key === 'includeLower' || key === 'noConsecutive' || key === 'usePassphrase' || key === 'passphraseUseNumbers' || key === 'passphraseUseSpecial' || key === 'enableHistory') {
config[key] = value === 'true';
} else if (key === 'length' || key === 'numberCount' || key === 'wordCount') {
config[key] = parseInt(value);
} else {
config[key] = value;
}
}
setConfig(config);
return;
}
// Then try cookies
const cookies = document.cookie.split(';');
for (const cookie of cookies) {
const [name, value] = cookie.trim().split('=');
if (name === 'passwordGenSettings') {
try {
const config = JSON.parse(decodeURIComponent(value));
setConfig(config);
currentMode = config.mode || 'passphrase'; // Default to passphrase
switchTab(currentMode);
} catch (e) {
console.error('Failed to parse cookie settings:', e);
// Set defaults on error
switchTab('passphrase');
}
break;
}
}
}
function updateShareUrl() {
const config = getConfig();
const params = new URLSearchParams();
for (const [key, value] of Object.entries(config)) {
params.set(key, value.toString());
}
const newUrl = window.location.pathname + '?' + params.toString();
// Update browser URL without page reload
if (window.history && window.history.pushState) {
window.history.replaceState({}, '', newUrl);
}
}
// Add event listeners to update settings
document.querySelectorAll('input, select').forEach(element => {
element.addEventListener('change', function() {
saveSettings();
updateShareUrl();
});
});
async function generatePassword() {
const config = getConfig();
try {
const response = await fetch('/api/password', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(config)
});
if (!response.ok) {
throw new Error('Failed to generate password');
}
const result = await response.text();
document.getElementById('passwordDisplay').textContent = result;
document.getElementById('copyBtn').style.display = 'inline-block';
// Save to history
const passwordType = config.usePassphrase ? 'Passphrase' : 'Random';
savePasswordToHistory(result, passwordType);
// Update strength indicator
updateStrengthIndicator(result, config);
// Refresh word list info if using passphrase
if (config.usePassphrase) {
loadWordListInfo();
}
} catch (error) {
document.getElementById('passwordDisplay').textContent = 'Error: ' + error.message;
document.getElementById('copyBtn').style.display = 'none';
}
}
function updateStrengthIndicator(password, config) {
let score = 0;
let feedback = [];
// Length score
if (password.length >= 12) score += 25;
else if (password.length >= 8) score += 15;
else score += 5;
// Character variety
if (/[a-z]/.test(password)) score += 10;
if (/[A-Z]/.test(password)) score += 10;
if (/[0-9]/.test(password)) score += 10;
if (/[^a-zA-Z0-9]/.test(password)) score += 15;
// Length bonus
if (password.length >= 16) score += 10;
if (password.length >= 20) score += 10;
// Passphrase bonus
if (config.usePassphrase) score += 10;
// No consecutive bonus
if (config.noConsecutive) score += 5;
let strength, color;
if (score >= 80) {
strength = "Very Strong 💪";
color = "#00aa44";
} else if (score >= 60) {
strength = "Strong 🔒";
color = "#007acc";
} else if (score >= 40) {
strength = "Medium ⚠️";
color = "#ff8800";
} else {
strength = "Weak ❌";
color = "#cc0000";
}
document.getElementById('strengthIndicator').innerHTML =
`<span style="color: ${color}">${strength}</span> (Score: ${score}/100)`;
}
function copyPassword() {
const passwordText = document.getElementById('passwordDisplay').textContent;
navigator.clipboard.writeText(passwordText).then(function() {
const btn = document.getElementById('copyBtn');
btn.textContent = 'Copied! ✓';
btn.classList.add('copied');
setTimeout(function() {
btn.textContent = 'Copy to Clipboard';
btn.classList.remove('copied');
}, 2000);
}).catch(function(err) {
console.error('Failed to copy: ', err);
});
}
// Password History Management
function savePasswordToHistory(password, type) {
if (!document.getElementById('enableHistory').checked) {
return;
}
const history = getPasswordHistory();
const timestamp = new Date().toLocaleString();
history.unshift({
timestamp: timestamp,
password: password,
type: type,
date: new Date().getTime()
});
// Keep only last 50 passwords and remove entries older than 7 days
const sevenDaysAgo = new Date().getTime() - (7 * 24 * 60 * 60 * 1000);
const filteredHistory = history
.filter(item => item.date > sevenDaysAgo)
.slice(0, 50);
localStorage.setItem('passwordHistory', JSON.stringify(filteredHistory));
updateHistoryDisplay();
}
function getPasswordHistory() {
try {
const history = localStorage.getItem('passwordHistory');
return history ? JSON.parse(history) : [];
} catch (e) {
console.error('Failed to parse password history:', e);
return [];
}
}
function clearPasswordHistory() {
localStorage.removeItem('passwordHistory');
updateHistoryDisplay();
}
function updateHistoryDisplay() {
const historyEnabled = document.getElementById('enableHistory').checked;
const historySection = document.getElementById('historySection');
if (!historyEnabled) {
historySection.style.display = 'none';
return;
}
const history = getPasswordHistory();
const tbody = document.getElementById('historyBody');
if (history.length === 0) {
historySection.style.display = 'none';
return;
}
historySection.style.display = 'block';
tbody.innerHTML = '';
history.forEach(item => {
const row = document.createElement('tr');
row.innerHTML = `
<td style="padding: 8px; border: 1px solid #444; font-size: 12px; color: #ccc;">${item.timestamp}</td>
<td style="padding: 8px; border: 1px solid #444; font-family: monospace; word-break: break-all; color: #00ff88;">${item.password}</td>
<td style="padding: 8px; border: 1px solid #444; font-size: 12px; color: #ccc;">${item.type}</td>
<td style="padding: 8px; border: 1px solid #444;">
<button onclick="copyPasswordFromHistory('${item.password}')" style="background: #007acc; color: white; border: none; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 12px;">Copy</button>
</td>
`;
tbody.appendChild(row);
});
}
function copyPasswordFromHistory(password) {
navigator.clipboard.writeText(password).then(function() {
// Visual feedback could be added here
console.log('Password copied from history');
}).catch(function(err) {
console.error('Failed to copy password from history: ', err);
});
}
// History toggle event listener
document.getElementById('enableHistory').addEventListener('change', function() {
if (!this.checked) {
clearPasswordHistory();
}
updateHistoryDisplay();
saveSettings();
});
// Load settings from cookies and URL parameters
window.addEventListener('load', function() {
loadSettings();
updateShareUrl();
loadWordListInfo();
updateHistoryDisplay();
// Auto-generate if URL has parameters
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.toString()) {
generatePassword();
}
});
</script>
</body>
</html>