Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Extend PasswordField with diceware option (#776)
Leendert de Borstefe05cc46f22
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsxindex e8ba8bb32..46e5d9708 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsx@@ -5,8 +5,12 @@ import PasswordConfigDialog from '@/entrypoints/popup/components/Dialogs/Passworimport { 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';+import * as RustCore from '@/utils/RustCore';++const MIN_WORD_COUNT = 3;+const MAX_WORD_COUNT = 10;+const DEFAULT_WORD_COUNT = 4;interface IPasswordFieldProps {id: string;@@ -84,10 +88,9 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({void loadSettings();}, [dbContext.sqliteClient, initialSettings]);- const generatePassword = useCallback((settings: PasswordSettings) => {+ const generatePassword = useCallback(async (settings: PasswordSettings): Promise<void> => {try {- const passwordGenerator = CreatePasswordGenerator(settings);- const password = passwordGenerator.generateRandomPassword();+ const password = await RustCore.generatePassword(settings);onChange(password);setShowPassword(true);} catch (error) {@@ -95,6 +98,8 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({}}, [onChange, setShowPassword]);+ const isDiceware = currentSettings?.Type === 'diceware';+const handleLengthChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {if (!currentSettings) {return;@@ -108,14 +113,29 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({onSettingsChange?.(newSettings);// Always generate password when length changes- generatePassword(newSettings);+ void generatePassword(newSettings);+ }, [currentSettings, generatePassword, onSettingsChange]);++ const handleWordCountChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {+ if (!currentSettings) {+ return;+ }+ const wordCount = parseInt(e.target.value, 10);+ const newSettings = { ...currentSettings, WordCount: wordCount };+ setCurrentSettings(newSettings);++ // Notify parent of settings change for persistence+ onSettingsChange?.(newSettings);++ // Always regenerate passphrase when word count changes+ void generatePassword(newSettings);}, [currentSettings, generatePassword, onSettingsChange]);const handleRegeneratePassword = useCallback(() => {if (!currentSettings) {return;}- generatePassword(currentSettings);+ void generatePassword(currentSettings);}, [generatePassword, currentSettings]);const handleConfiguredPassword = useCallback((password: string) => {@@ -202,15 +222,15 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({</div></div>- {/* Inline Password Length Slider */}+ {/* Inline Slider: password length (basic) or word count (diceware) */}<div className="pt-2"><div className="flex items-center justify-between mb-2"><label htmlFor={`${id}-length`} className="text-sm font-medium text-gray-700 dark:text-gray-300">- {t('items.passwordLength')}+ {isDiceware ? t('items.wordCount') : t('items.passwordLength')}</label><div className="flex items-center gap-2"><span className="text-sm text-gray-600 dark:text-gray-400 font-mono">- {currentSettings.Length}+ {isDiceware ? (currentSettings.WordCount ?? DEFAULT_WORD_COUNT) : currentSettings.Length}</span><buttontype="button"@@ -225,16 +245,29 @@ const PasswordField: React.FC<IPasswordFieldProps> = ({</button></div></div>- <input- type="range"- id={`${id}-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"- />+ {isDiceware ? (+ <input+ type="range"+ id={`${id}-length`}+ min={MIN_WORD_COUNT}+ max={MAX_WORD_COUNT}+ step="1"+ value={currentSettings.WordCount ?? DEFAULT_WORD_COUNT}+ onChange={handleWordCountChange}+ className="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"+ />+ ) : (+ <input+ type="range"+ id={`${id}-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"+ />+ )}</div>{/* Error Message */}