28 lines
1.5 KiB
JavaScript
28 lines
1.5 KiB
JavaScript
// ═══════════════════════════════════════════════════════
|
|
// Password Generator
|
|
// ═══════════════════════════════════════════════════════
|
|
async function generatePassword() {
|
|
const d = await apiPost('/api/password', {
|
|
length: parseInt(document.getElementById('pwLength').value),
|
|
uppercase: document.getElementById('pwUpper').checked,
|
|
lowercase: document.getElementById('pwLower').checked,
|
|
numbers: document.getElementById('pwNumbers').checked,
|
|
symbols: document.getElementById('pwSymbols').checked,
|
|
count: 5
|
|
});
|
|
if (d.success) {
|
|
document.getElementById('pwDisplay').textContent = d.passwords[0];
|
|
// Strength
|
|
const len = d.passwords[0].length;
|
|
const str = len >= 20 ? 100 : len >= 12 ? 75 : len >= 8 ? 50 : 25;
|
|
const colors = { 25: 'var(--red)', 50: 'var(--orange)', 75: 'var(--yellow)', 100: 'var(--green)' };
|
|
const fill = document.getElementById('pwStrength');
|
|
fill.style.width = str + '%';
|
|
fill.style.background = colors[str];
|
|
// Batch
|
|
document.getElementById('pwBatch').innerHTML = '<div class="panel-label">More Passwords</div>' +
|
|
d.passwords.slice(1).map(pw => `<div class="result-row"><div class="value" onclick="copyText(this.textContent)" style="max-width:100%;text-align:left;">${pw}</div></div>`).join('');
|
|
}
|
|
}
|
|
|