Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add advanced password generator options to content script (#883)
Leendert de Borst11506147221a
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.tsindex 44190f0a8..35c679a32 100644--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts@@ -6,7 +6,7 @@ import { fillCredential } from '@/entrypoints/contentScript/Form';import { DISABLED_SITES_KEY, TEMPORARY_DISABLED_SITES_KEY, GLOBAL_AUTOFILL_POPUP_ENABLED_KEY, VAULT_LOCKED_DISMISS_UNTIL_KEY, LAST_CUSTOM_EMAIL_KEY, LAST_CUSTOM_USERNAME_KEY } from '@/utils/Constants';import { CreateIdentityGenerator } from '@/utils/dist/shared/identity-generator';import type { Credential } from '@/utils/dist/shared/models/vault';-import { CreatePasswordGenerator, PasswordGenerator } from '@/utils/dist/shared/password-generator';+import { CreatePasswordGenerator, PasswordGenerator, PasswordSettings } from '@/utils/dist/shared/password-generator';import { FormDetector } from '@/utils/formDetector/FormDetector';import { SqliteClient } from '@/utils/SqliteClient';import { CredentialsResponse } from '@/utils/types/messaging/CredentialsResponse';@@ -908,6 +908,22 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootCon</svg></button></div>++ <div class="av-password-length-container">+ <div class="av-password-length-header">+ <label for="password-length-slider">Password length</label>+ <div class="av-password-length-controls">+ <span id="password-length-value" class="av-password-length-value">12</span>+ <button id="password-config-btn" class="av-password-config-btn" title="Change password complexity">+ <svg class="av-icon" viewBox="0 0 24 24">+ <path d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path>+ <path d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>+ </svg>+ </button>+ </div>+ </div>+ <input type="range" id="password-length-slider" min="8" max="64" value="12" class="av-password-length-slider">+ </div></div><div class="av-create-popup-actions"><button id="custom-cancel-btn" class="av-create-popup-cancel">${cancelText}</button>@@ -979,18 +995,28 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootCon// Get password settings from backgroundlet passwordGenerator: PasswordGenerator;+ let currentPasswordSettings: PasswordSettings = {+ Length: 12,+ UseLowercase: true,+ UseUppercase: true,+ UseNumbers: true,+ UseSpecialChars: true,+ UseNonAmbiguousChars: true+ };+sendMessage('GET_PASSWORD_SETTINGS', {}, 'background').then((response) => {const passwordSettingsResponse = response as PasswordSettingsResponse;- passwordGenerator = CreatePasswordGenerator(passwordSettingsResponse.settings ?? {- Length: 12,- UseLowercase: true,- UseUppercase: true,- UseNumbers: true,- UseSpecialChars: true,- UseNonAmbiguousChars: true- });+ currentPasswordSettings = passwordSettingsResponse.settings ?? currentPasswordSettings;+ passwordGenerator = CreatePasswordGenerator(currentPasswordSettings);++ // Update UI with loaded settings+ const lengthSlider = popup.querySelector('#password-length-slider') as HTMLInputElement;+ const lengthValue = popup.querySelector('#password-length-value') as HTMLSpanElement;+ lengthSlider.value = currentPasswordSettings.Length.toString();+ lengthValue.textContent = currentPasswordSettings.Length.toString();+// Generate initial password after settings are loaded- passwordGenerator.generateRandomPassword();+ generatePassword();});/**@@ -1010,6 +1036,28 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootCon// Handle regenerate button clickregenerateBtn.addEventListener('click', generatePassword);+ // Handle password length slider+ const lengthSlider = popup.querySelector('#password-length-slider') as HTMLInputElement;+ const lengthValue = popup.querySelector('#password-length-value') as HTMLSpanElement;++ lengthSlider.addEventListener('input', () => {+ const newLength = parseInt(lengthSlider.value, 10);+ currentPasswordSettings.Length = newLength;+ lengthValue.textContent = newLength.toString();++ // Regenerate password with new settings+ if (passwordGenerator) {+ passwordGenerator = CreatePasswordGenerator(currentPasswordSettings);+ generatePassword();+ }+ });++ // Handle advanced configuration button+ const configBtn = popup.querySelector('#password-config-btn') as HTMLButtonElement;+ configBtn.addEventListener('click', () => {+ showPasswordConfigDialog();+ });+// Add password visibility toggle functionalityconst passwordInput = popup.querySelector('#password-preview') as HTMLInputElement;@@ -1041,6 +1089,144 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootContoggleVisibilityBtn.addEventListener('click', togglePasswordVisibility);+ /**+ * Show password configuration dialog+ */+ const showPasswordConfigDialog = (): void => {+ // Create dialog overlay+ const dialogOverlay = document.createElement('div');+ dialogOverlay.className = 'av-password-config-overlay';++ const dialog = document.createElement('div');+ dialog.className = 'av-password-config-dialog';++ dialog.innerHTML = `+ <div class="av-password-config-header">+ <h3>Change password complexity</h3>+ <button class="av-password-config-close">+ <svg class="av-icon" viewBox="0 0 24 24">+ <path d="M6 18L18 6M6 6l12 12"/>+ </svg>+ </button>+ </div>++ <div class="av-password-config-content">+ <div class="av-password-preview-section">+ <input type="text" id="config-preview" class="av-password-config-preview" readonly>+ <button id="config-refresh" class="av-password-config-refresh" title="Generate new preview">+ <svg class="av-icon" viewBox="0 0 24 24">+ <path d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>+ </svg>+ </button>+ </div>++ <div class="av-password-config-options">+ <div class="av-password-config-toggles">+ <button class="av-password-config-toggle ${currentPasswordSettings.UseLowercase ? 'active' : ''}" data-setting="UseLowercase" title="Include lowercase letters">+ <span>a-z</span>+ </button>+ <button class="av-password-config-toggle ${currentPasswordSettings.UseUppercase ? 'active' : ''}" data-setting="UseUppercase" title="Include uppercase letters">+ <span>A-Z</span>+ </button>+ <button class="av-password-config-toggle ${currentPasswordSettings.UseNumbers ? 'active' : ''}" data-setting="UseNumbers" title="Include numbers">+ <span>0-9</span>+ </button>+ <button class="av-password-config-toggle ${currentPasswordSettings.UseSpecialChars ? 'active' : ''}" data-setting="UseSpecialChars" title="Include special characters">+ <span>!@#</span>+ </button>+ </div>++ <div class="av-password-config-checkbox">+ <label>+ <input type="checkbox" id="avoid-ambiguous" ${currentPasswordSettings.UseNonAmbiguousChars ? 'checked' : ''}>+ <span>Avoid ambiguous characters (o, 0, etc.)</span>+ </label>+ </div>+ </div>++ <div class="av-password-config-actions">+ <button id="config-use-btn" class="av-password-config-use">+ <svg class="av-icon" viewBox="0 0 24 24">+ <path d="M15 13l-3 3m0 0l-3-3m3 3V8m0 13a9 9 0 110-18 9 9 0 010 18z"/>+ </svg>+ Use+ </button>+ </div>+ </div>+ `;++ dialogOverlay.appendChild(dialog);+ popup.appendChild(dialogOverlay);++ // Generate initial preview+ const configPreview = dialog.querySelector('#config-preview') as HTMLInputElement;+ /**+ * Update the config preview.+ */+ const updateConfigPreview = (): void => {+ if (passwordGenerator) {+ passwordGenerator = CreatePasswordGenerator(currentPasswordSettings);+ configPreview.value = passwordGenerator.generateRandomPassword();+ }+ };+ updateConfigPreview();++ // Handle toggle buttons+ dialog.querySelectorAll('.av-password-config-toggle').forEach(toggle => {+ toggle.addEventListener('click', () => {+ const setting = (toggle as HTMLElement).dataset.setting;+ if (setting) {+ currentPasswordSettings[setting] = !currentPasswordSettings[setting];+ toggle.classList.toggle('active', currentPasswordSettings[setting]);+ updateConfigPreview();+ }+ });+ });++ // Handle checkbox+ const avoidAmbiguousCheckbox = dialog.querySelector('#avoid-ambiguous') as HTMLInputElement;+ avoidAmbiguousCheckbox.addEventListener('change', () => {+ currentPasswordSettings.UseNonAmbiguousChars = avoidAmbiguousCheckbox.checked;+ updateConfigPreview();+ });++ // Handle refresh button+ const refreshBtn = dialog.querySelector('#config-refresh') as HTMLButtonElement;+ refreshBtn.addEventListener('click', updateConfigPreview);++ // Handle use button+ const useBtn = dialog.querySelector('#config-use-btn') as HTMLButtonElement;+ useBtn.addEventListener('click', () => {+ passwordPreview.value = configPreview.value;+ passwordPreview.type = 'text';+ passwordPreview.dataset.isGenerated = 'true';+ updateVisibilityIcon(true);++ // Update main password generator+ passwordGenerator = CreatePasswordGenerator(currentPasswordSettings);++ // Update slider value+ lengthSlider.value = currentPasswordSettings.Length.toString();+ lengthValue.textContent = currentPasswordSettings.Length.toString();++ // Close dialog+ dialogOverlay.remove();+ });++ // Handle close button+ const closeBtn = dialog.querySelector('.av-password-config-close') as HTMLButtonElement;+ closeBtn.addEventListener('click', () => {+ dialogOverlay.remove();+ });++ // Handle click outside to close+ dialogOverlay.addEventListener('click', (e) => {+ if (e.target === dialogOverlay) {+ dialogOverlay.remove();+ }+ });+ };+/*** Handle password input changes*/diff --git a/apps/browser-extension/src/entrypoints/contentScript/style.css b/apps/browser-extension/src/entrypoints/contentScript/style.cssindex cf6eebb51..88c79c9c9 100644--- a/apps/browser-extension/src/entrypoints/contentScript/style.css+++ b/apps/browser-extension/src/entrypoints/contentScript/style.css@@ -897,4 +897,288 @@ body {stroke-width: 2;stroke-linecap: round;stroke-linejoin: round;+}++/* Password Configuration Styles */+.av-password-length-container {+ margin-top: 12px;+ padding-top: 8px;+}++.av-password-length-header {+ display: flex;+ align-items: center;+ justify-content: space-between;+ margin-bottom: 8px;+}++.av-password-length-header label {+ font-size: 0.875rem;+ font-weight: 500;+ color: #9ca3af;+ margin: 0;+}++.av-password-length-controls {+ display: flex;+ align-items: center;+ gap: 8px;+}++.av-password-length-value {+ font-size: 0.875rem;+ color: #e5e7eb;+ font-family: 'Courier New', monospace;+ min-width: 24px;+ text-align: center;+}++.av-password-config-btn {+ display: flex;+ align-items: center;+ justify-content: center;+ padding: 4px;+ background: none;+ border: none;+ border-radius: 4px;+ cursor: pointer;+ color: #9ca3af;+ transition: color 0.2s ease, background-color 0.2s ease;+}++.av-password-config-btn:hover {+ color: #e5e7eb;+ background-color: rgba(75, 85, 99, 0.3);+}++.av-password-config-btn .av-icon {+ width: 16px;+ height: 16px;+}++.av-password-length-slider {+ width: 100%;+ height: 8px;+ background: #374151;+ border-radius: 4px;+ appearance: none;+ cursor: pointer;+ outline: none;+}++.av-password-length-slider::-webkit-slider-thumb {+ appearance: none;+ height: 16px;+ width: 16px;+ border-radius: 50%;+ background: #d68338;+ cursor: pointer;+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);+}++.av-password-length-slider::-moz-range-thumb {+ height: 16px;+ width: 16px;+ border-radius: 50%;+ background: #d68338;+ cursor: pointer;+ border: none;+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);+}++/* Password Config Dialog */+.av-password-config-overlay {+ position: fixed;+ top: 0;+ left: 0;+ right: 0;+ bottom: 0;+ background: rgba(0, 0, 0, 0.6);+ z-index: 2147483647;+ display: flex;+ align-items: center;+ justify-content: center;+}++.av-password-config-dialog {+ background: #1f2937;+ border: 1px solid #374151;+ border-radius: 8px;+ box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);+ width: 400px;+ max-width: 90vw;+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;+}++.av-password-config-header {+ display: flex;+ align-items: center;+ justify-content: space-between;+ padding: 16px 20px;+ border-bottom: 1px solid #374151;+}++.av-password-config-header h3 {+ margin: 0;+ font-size: 16px;+ font-weight: 600;+ color: #f8f9fa;+}++.av-password-config-close {+ background: none;+ border: none;+ padding: 4px;+ cursor: pointer;+ color: #9ca3af;+ border-radius: 4px;+ transition: color 0.2s ease, background-color 0.2s ease;+}++.av-password-config-close:hover {+ color: #e5e7eb;+ background-color: #374151;+}++.av-password-config-close .av-icon {+ width: 16px;+ height: 16px;+}++.av-password-config-content {+ padding: 20px;+}++.av-password-preview-section {+ display: flex;+ align-items: center;+ gap: 8px;+ margin-bottom: 20px;+}++.av-password-config-preview {+ flex: 1;+ padding: 10px 12px;+ border: 1px solid #374151;+ border-radius: 6px;+ background: #374151;+ color: #f8f9fa;+ font-size: 14px;+ font-family: 'Courier New', monospace;+ outline: none;+}++.av-password-config-refresh {+ display: flex;+ align-items: center;+ justify-content: center;+ padding: 10px;+ background: #374151;+ border: none;+ border-radius: 6px;+ cursor: pointer;+ color: #e5e7eb;+ transition: background-color 0.2s ease;+}++.av-password-config-refresh:hover {+ background-color: #4b5563;+}++.av-password-config-refresh .av-icon {+ width: 16px;+ height: 16px;+}++.av-password-config-options {+ margin-bottom: 20px;+}++.av-password-config-toggles {+ display: grid;+ grid-template-columns: repeat(2, 1fr);+ gap: 8px;+ margin-bottom: 16px;+}++.av-password-config-toggle {+ display: flex;+ align-items: center;+ justify-content: center;+ padding: 10px;+ background: #374151;+ border: none;+ border-radius: 6px;+ cursor: pointer;+ color: #9ca3af;+ transition: all 0.2s ease;+ font-family: 'Courier New', monospace;+ font-size: 14px;+ font-weight: 500;+}++.av-password-config-toggle:hover {+ background-color: #4b5563;+}++.av-password-config-toggle.active {+ background-color: #d68338;+ color: white;+}++.av-password-config-toggle.active:hover {+ background-color: #c97731;+}++.av-password-config-checkbox {+ display: flex;+ align-items: center;+ gap: 8px;+}++.av-password-config-checkbox label {+ display: flex;+ align-items: center;+ gap: 8px;+ cursor: pointer;+ font-size: 14px;+ color: #e5e7eb;+ margin: 0;+}++.av-password-config-checkbox input[type="checkbox"] {+ width: 16px;+ height: 16px;+ accent-color: #d68338;+ cursor: pointer;+}++.av-password-config-actions {+ display: flex;+ justify-content: flex-end;+}++.av-password-config-use {+ display: flex;+ align-items: center;+ justify-content: center;+ gap: 6px;+ padding: 10px 16px;+ background: #6b7280;+ border: none;+ border-radius: 6px;+ cursor: pointer;+ color: white;+ font-size: 14px;+ font-weight: 500;+ transition: background-color 0.2s ease;+}++.av-password-config-use:hover {+ background-color: #4b5563;+}++.av-password-config-use .av-icon {+ width: 16px;+ height: 16px;}\ No newline at end of file