Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Increase max password generator length to 256 chars in browser extension (#1701)
Leendert de Borst438528a123a7
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.tsindex 4832ac56c..493625581 100644--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts@@ -9,6 +9,7 @@ import { ItemTypes, FieldKey, createSystemField } from '@/utils/dist/core/modelsimport { CreatePasswordGenerator, PasswordGenerator, PasswordSettings } from '@/utils/dist/core/password-generator';import { getAllFaviconLinks } from '@/utils/favicon';import { LocalPreferencesService } from '@/utils/LocalPreferencesService';+import { sliderToLength, lengthToSlider, SLIDER_MIN, SLIDER_MAX } from '@/utils/passwordLengthSlider';import { ClickValidator } from '@/utils/security/ClickValidator';import { ServiceDetectionUtility } from '@/utils/serviceDetection/ServiceDetectionUtility';import { SqliteClient } from '@/utils/SqliteClient';@@ -1026,7 +1027,7 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootCon</button></div></div>- <input type="range" id="password-length-slider" min="8" max="64" value="12" class="av-password-length-slider">+ <input type="range" id="password-length-slider" min="${SLIDER_MIN}" max="${SLIDER_MAX}" step="0.1" value="${lengthToSlider(12)}" class="av-password-length-slider"></div></div><div class="av-create-popup-actions">@@ -1246,7 +1247,7 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootCon// Update UI with loaded settingsconst lengthSlider = popup.querySelector('#password-length-slider') as HTMLInputElement;const lengthValue = popup.querySelector('#password-length-value') as HTMLSpanElement;- lengthSlider.value = currentPasswordSettings.Length.toString();+ lengthSlider.value = lengthToSlider(currentPasswordSettings.Length).toString();lengthValue.textContent = currentPasswordSettings.Length.toString();// Generate initial password after settings are loaded@@ -1275,7 +1276,8 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootConconst lengthValue = popup.querySelector('#password-length-value') as HTMLSpanElement;lengthSlider.addEventListener('input', () => {- const newLength = parseInt(lengthSlider.value, 10);+ const sliderValue = parseFloat(lengthSlider.value);+ const newLength = sliderToLength(sliderValue);currentPasswordSettings.Length = newLength;lengthValue.textContent = newLength.toString();@@ -1466,7 +1468,7 @@ export async function createAliasCreationPopup(suggestedNames: string[], rootConpasswordGenerator = CreatePasswordGenerator(currentPasswordSettings);// Update slider value- lengthSlider.value = currentPasswordSettings.Length.toString();+ lengthSlider.value = lengthToSlider(currentPasswordSettings.Length).toString();lengthValue.textContent = currentPasswordSettings.Length.toString();// Close dialogdiff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsxindex c5626497f..5680bc42b 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsx@@ -6,6 +6,7 @@ import { useDb } from '@/entrypoints/popup/context/DbContext';import type { PasswordSettings } from '@/utils/dist/core/models/vault';import { CreatePasswordGenerator } from '@/utils/dist/core/password-generator';+import { sliderToLength, lengthToSlider, SLIDER_MIN, SLIDER_MAX } from '@/utils/passwordLengthSlider';interface IPasswordFieldProps {id: string;@@ -98,7 +99,8 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({if (!currentSettings) {return;}- const length = parseInt(e.target.value, 10);+ const sliderValue = parseFloat(e.target.value);+ const length = sliderToLength(sliderValue);const newSettings = { ...currentSettings, Length: length };setCurrentSettings(newSettings);@@ -226,9 +228,10 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({<inputtype="range"id={`${id}-length`}- min="8"- max="64"- value={currentSettings.Length}+ min={SLIDER_MIN}+ max={SLIDER_MAX}+ step="0.1"+ value={lengthToSlider(currentSettings.Length)}onChange={handleLengthChange}className="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"/>diff --git a/apps/browser-extension/src/utils/passwordLengthSlider.ts b/apps/browser-extension/src/utils/passwordLengthSlider.tsnew file mode 100644index 000000000..d3a38260b--- /dev/null+++ b/apps/browser-extension/src/utils/passwordLengthSlider.ts@@ -0,0 +1,57 @@+/**+ * Utility functions for password length slider with non-linear scaling.+ *+ * The slider uses a power curve to provide fine-grained control at lower values+ * (where most users operate, e.g., 12-32 chars) and coarser control at higher values+ * (64-256 chars).+ *+ * This makes it easy to select common password lengths while still allowing+ * very long passwords when needed.+ */++/** Minimum password length */+export const MIN_PASSWORD_LENGTH = 8;++/** Maximum password length */+export const MAX_PASSWORD_LENGTH = 256;++/** Slider minimum value (internal representation) */+export const SLIDER_MIN = 0;++/** Slider maximum value (internal representation) */+export const SLIDER_MAX = 100;++/**+ * Exponent for the power curve.+ * Higher values = more precision at lower lengths.+ * 2.0 gives a good balance where ~50% slider = ~70 chars+ */+const EXPONENT = 2.0;++/**+ * Convert a slider position (0-100) to an actual password length (8-256).+ * Uses a power curve for non-linear scaling.+ *+ * @param sliderValue - The slider position (0-100)+ * @returns The password length (8-256)+ */+export function sliderToLength(sliderValue: number): number {+ const normalized = Math.max(0, Math.min(1, sliderValue / SLIDER_MAX));+ const curved = Math.pow(normalized, EXPONENT);+ const length = MIN_PASSWORD_LENGTH + curved * (MAX_PASSWORD_LENGTH - MIN_PASSWORD_LENGTH);+ return Math.round(length);+}++/**+ * Convert a password length (8-256) to a slider position (0-100).+ * Inverse of sliderToLength.+ *+ * @param length - The password length (8-256)+ * @returns The slider position (0-100)+ */+export function lengthToSlider(length: number): number {+ const clampedLength = Math.max(MIN_PASSWORD_LENGTH, Math.min(MAX_PASSWORD_LENGTH, length));+ const normalized = (clampedLength - MIN_PASSWORD_LENGTH) / (MAX_PASSWORD_LENGTH - MIN_PASSWORD_LENGTH);+ const curved = Math.pow(normalized, 1 / EXPONENT);+ return curved * SLIDER_MAX;+}