Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add core shared defaults for password generator (#776)

Leendert de Borst89162a007fa7
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Dialogs/PasswordConfigDialog.tsx b/apps/browser-extension/src/entrypoints/popup/components/Dialogs/PasswordConfigDialog.tsx
index 48de865bb..2edc119b8 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Dialogs/PasswordConfigDialog.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Dialogs/PasswordConfigDialog.tsx
@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
import ModalWrapper from '@/entrypoints/popup/components/Dialogs/ModalWrapper';
+import { MIN_WORD_COUNT, MAX_WORD_COUNT, DEFAULT_WORD_COUNT } from '@/utils/dist/core/models/defaults';
import type {
PasswordSettings,
PasswordGeneratorType,
@@ -12,11 +13,6 @@ import type {
} from '@/utils/dist/core/models/vault';
import * as RustCore from '@/utils/RustCore';
-/** Inclusive bounds for the Diceware word-count slider. */
-const MIN_WORD_COUNT = 3;
-const MAX_WORD_COUNT = 10;
-const DEFAULT_WORD_COUNT = 5;
-
const CAPITALIZATION_OPTIONS: DicewareCapitalization[] = ['Lowercase', 'TitleCase', 'Uppercase'];
const SEPARATOR_OPTIONS: DicewareSeparator[] = ['Dash', 'Space', 'Underscore', 'Dot', 'None'];
const SALT_OPTIONS: DicewareSalt[] = ['None', 'Prefix', 'Sprinkle', 'Suffix'];
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsx
index 51557f367..92b422978 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordField.tsx
@@ -4,14 +4,11 @@ import { useTranslation } from 'react-i18next';
import PasswordConfigDialog from '@/entrypoints/popup/components/Dialogs/PasswordConfigDialog';
import { useDb } from '@/entrypoints/popup/context/DbContext';
+import { MIN_WORD_COUNT, MAX_WORD_COUNT, DEFAULT_WORD_COUNT } from '@/utils/dist/core/models/defaults';
import type { PasswordSettings } from '@/utils/dist/core/models/vault';
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 = 5;
-
interface IPasswordFieldProps {
id: string;
label: string;
diff --git a/apps/browser-extension/src/utils/PasswordLengthSlider.ts b/apps/browser-extension/src/utils/PasswordLengthSlider.ts
index d3a38260b..ac422338a 100644
--- a/apps/browser-extension/src/utils/PasswordLengthSlider.ts
+++ b/apps/browser-extension/src/utils/PasswordLengthSlider.ts
@@ -8,12 +8,7 @@
* 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;
+import { MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH } from '@/utils/dist/core/models/defaults';
/** Slider minimum value (internal representation) */
export const SLIDER_MIN = 0;
diff --git a/apps/browser-extension/src/utils/db/repositories/SettingsRepository.ts b/apps/browser-extension/src/utils/db/repositories/SettingsRepository.ts
index bcb623543..07b03b501 100644
--- a/apps/browser-extension/src/utils/db/repositories/SettingsRepository.ts
+++ b/apps/browser-extension/src/utils/db/repositories/SettingsRepository.ts
@@ -1,3 +1,4 @@
+import { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT } from '@/utils/dist/core/models/defaults';
import type { EncryptionKey, PasswordSettings, TotpCode, Attachment } from '@/utils/dist/core/models/vault';
import { BaseRepository } from '../BaseRepository';
@@ -60,14 +61,14 @@ export class SettingsRepository extends BaseRepository {
const settingsJson = this.getSetting('PasswordGenerationSettings');
const defaultSettings: PasswordSettings = {
- Length: 18,
+ Length: DEFAULT_PASSWORD_LENGTH,
UseLowercase: true,
UseUppercase: true,
UseNumbers: true,
UseSpecialChars: true,
UseNonAmbiguousChars: false,
Type: 'basic',
- WordCount: 5,
+ WordCount: DEFAULT_WORD_COUNT,
Language: 'English',
Capitalization: 'Lowercase',
Separator: 'Dash',
diff --git a/apps/browser-extension/src/utils/dist/core/models/defaults/index.d.ts b/apps/browser-extension/src/utils/dist/core/models/defaults/index.d.ts
new file mode 100644
index 000000000..9a56cdf42
--- /dev/null
+++ b/apps/browser-extension/src/utils/dist/core/models/defaults/index.d.ts
@@ -0,0 +1,24 @@
+/**
+ * Single source of truth for the password-length and Diceware word-count
+ * defaults and UI slider ranges shared across every AliasVault client.
+ *
+ * This file is distributed by core/models/build.sh to all platforms including:
+ * - `core/rust/src/password_generator/defaults.rs` (Rust core)
+ * - `apps/server/Databases/AliasClientDb/Models/PasswordGeneratorDefaults.cs` (C# web client)
+ *
+ * The TypeScript clients (browser extension, mobile app) import the constants directly from `@/utils/dist/core/models/defaults`.
+ */
+/** Default length of a generated basic password. */
+declare const DEFAULT_PASSWORD_LENGTH = 18;
+/** Minimum password length offered by the UI length slider. */
+declare const MIN_PASSWORD_LENGTH = 8;
+/** Maximum password length (also the hard cap enforced by the generator). */
+declare const MAX_PASSWORD_LENGTH = 256;
+/** Default number of words in a generated Diceware passphrase. */
+declare const DEFAULT_WORD_COUNT = 5;
+/** Minimum number of words offered by the UI word-count slider. */
+declare const MIN_WORD_COUNT = 3;
+/** Maximum number of words (also the hard cap enforced by the generator). */
+declare const MAX_WORD_COUNT = 10;
+
+export { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT };
diff --git a/apps/browser-extension/src/utils/dist/core/models/defaults/index.js b/apps/browser-extension/src/utils/dist/core/models/defaults/index.js
new file mode 100644
index 000000000..fa6095500
--- /dev/null
+++ b/apps/browser-extension/src/utils/dist/core/models/defaults/index.js
@@ -0,0 +1,13 @@
+// <auto-generated>
+// This file was automatically generated. Do not edit manually.
+
+
+// src/defaults/PasswordGeneratorDefaults.ts
+var DEFAULT_PASSWORD_LENGTH = 18;
+var MIN_PASSWORD_LENGTH = 8;
+var MAX_PASSWORD_LENGTH = 256;
+var DEFAULT_WORD_COUNT = 5;
+var MIN_WORD_COUNT = 3;
+var MAX_WORD_COUNT = 10;
+
+export { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT };
diff --git a/apps/browser-extension/src/utils/dist/core/models/vault/index.d.ts b/apps/browser-extension/src/utils/dist/core/models/vault/index.d.ts
index 71c969f90..9c8824821 100644
--- a/apps/browser-extension/src/utils/dist/core/models/vault/index.d.ts
+++ b/apps/browser-extension/src/utils/dist/core/models/vault/index.d.ts
@@ -60,7 +60,7 @@ type PasswordSettings = {
*/
Type?: PasswordGeneratorType;
/**
- * Number of words in the passphrase (diceware generator). Defaults to 4.
+ * Number of words in the passphrase (diceware generator).
*/
WordCount?: number;
/**
diff --git a/apps/mobile-app/utils/PasswordLengthSlider.ts b/apps/mobile-app/utils/PasswordLengthSlider.ts
index d3a38260b..ac422338a 100644
--- a/apps/mobile-app/utils/PasswordLengthSlider.ts
+++ b/apps/mobile-app/utils/PasswordLengthSlider.ts
@@ -8,12 +8,7 @@
* 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;
+import { MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH } from '@/utils/dist/core/models/defaults';
/** Slider minimum value (internal representation) */
export const SLIDER_MIN = 0;
diff --git a/apps/mobile-app/utils/SqliteClient.ts b/apps/mobile-app/utils/SqliteClient.ts
index 1750e0b34..d4d595eed 100644
--- a/apps/mobile-app/utils/SqliteClient.ts
+++ b/apps/mobile-app/utils/SqliteClient.ts
@@ -2,6 +2,7 @@ import { Buffer } from 'buffer';
import type { EncryptionKeyDerivationParams, VaultMetadata } from '@/utils/dist/core/models/metadata';
import type { EncryptionKey, PasswordSettings } from '@/utils/dist/core/models/vault';
+import { DEFAULT_PASSWORD_LENGTH } from '@/utils/dist/core/models/defaults';
import { VaultSqlGenerator, VaultVersion, checkVersionCompatibility, extractVersionFromMigrationId } from '@/utils/dist/core/vault';
import { VaultVersionIncompatibleError } from '@/utils/types/errors/VaultVersionIncompatibleError';
@@ -407,7 +408,7 @@ class SqliteClient implements IDatabaseClient {
// Default settings if none found or parsing fails
const defaultSettings: PasswordSettings = {
- Length: 18,
+ Length: DEFAULT_PASSWORD_LENGTH,
UseLowercase: true,
UseUppercase: true,
UseNumbers: true,
diff --git a/apps/mobile-app/utils/db/repositories/SettingsRepository.ts b/apps/mobile-app/utils/db/repositories/SettingsRepository.ts
index 5120bb57d..ec10b10e3 100644
--- a/apps/mobile-app/utils/db/repositories/SettingsRepository.ts
+++ b/apps/mobile-app/utils/db/repositories/SettingsRepository.ts
@@ -1,4 +1,5 @@
import type { EncryptionKey, PasswordSettings, TotpCode, Attachment } from '@/utils/dist/core/models/vault';
+import { DEFAULT_PASSWORD_LENGTH } from '@/utils/dist/core/models/defaults';
import { BaseRepository } from '../BaseRepository';
@@ -109,7 +110,7 @@ export class SettingsRepository extends BaseRepository {
const settingsJson = await this.getSetting('PasswordGenerationSettings');
const defaultSettings: PasswordSettings = {
- Length: 18,
+ Length: DEFAULT_PASSWORD_LENGTH,
UseLowercase: true,
UseUppercase: true,
UseNumbers: true,
diff --git a/apps/mobile-app/utils/dist/core/models/defaults/index.d.ts b/apps/mobile-app/utils/dist/core/models/defaults/index.d.ts
new file mode 100644
index 000000000..9a56cdf42
--- /dev/null
+++ b/apps/mobile-app/utils/dist/core/models/defaults/index.d.ts
@@ -0,0 +1,24 @@
+/**
+ * Single source of truth for the password-length and Diceware word-count
+ * defaults and UI slider ranges shared across every AliasVault client.
+ *
+ * This file is distributed by core/models/build.sh to all platforms including:
+ * - `core/rust/src/password_generator/defaults.rs` (Rust core)
+ * - `apps/server/Databases/AliasClientDb/Models/PasswordGeneratorDefaults.cs` (C# web client)
+ *
+ * The TypeScript clients (browser extension, mobile app) import the constants directly from `@/utils/dist/core/models/defaults`.
+ */
+/** Default length of a generated basic password. */
+declare const DEFAULT_PASSWORD_LENGTH = 18;
+/** Minimum password length offered by the UI length slider. */
+declare const MIN_PASSWORD_LENGTH = 8;
+/** Maximum password length (also the hard cap enforced by the generator). */
+declare const MAX_PASSWORD_LENGTH = 256;
+/** Default number of words in a generated Diceware passphrase. */
+declare const DEFAULT_WORD_COUNT = 5;
+/** Minimum number of words offered by the UI word-count slider. */
+declare const MIN_WORD_COUNT = 3;
+/** Maximum number of words (also the hard cap enforced by the generator). */
+declare const MAX_WORD_COUNT = 10;
+
+export { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT };
diff --git a/apps/mobile-app/utils/dist/core/models/defaults/index.js b/apps/mobile-app/utils/dist/core/models/defaults/index.js
new file mode 100644
index 000000000..fa6095500
--- /dev/null
+++ b/apps/mobile-app/utils/dist/core/models/defaults/index.js
@@ -0,0 +1,13 @@
+// <auto-generated>
+// This file was automatically generated. Do not edit manually.
+
+
+// src/defaults/PasswordGeneratorDefaults.ts
+var DEFAULT_PASSWORD_LENGTH = 18;
+var MIN_PASSWORD_LENGTH = 8;
+var MAX_PASSWORD_LENGTH = 256;
+var DEFAULT_WORD_COUNT = 5;
+var MIN_WORD_COUNT = 3;
+var MAX_WORD_COUNT = 10;
+
+export { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT };
diff --git a/apps/mobile-app/utils/dist/core/models/vault/index.d.ts b/apps/mobile-app/utils/dist/core/models/vault/index.d.ts
index 71c969f90..9c8824821 100644
--- a/apps/mobile-app/utils/dist/core/models/vault/index.d.ts
+++ b/apps/mobile-app/utils/dist/core/models/vault/index.d.ts
@@ -60,7 +60,7 @@ type PasswordSettings = {
*/
Type?: PasswordGeneratorType;
/**
- * Number of words in the passphrase (diceware generator). Defaults to 4.
+ * Number of words in the passphrase (diceware generator).
*/
WordCount?: number;
/**
diff --git a/apps/server/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor b/apps/server/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor
index 5eb3e0b61..a12b658c0 100644
--- a/apps/server/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor
+++ b/apps/server/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor
@@ -117,8 +117,8 @@
/// <summary>
/// Inclusive bounds for the Diceware word-count slider.
/// </summary>
- private const int MinWordCount = 3;
- private const int MaxWordCount = 10;
+ private const int MinWordCount = AliasClientDb.Models.PasswordGeneratorDefaults.MinWordCount;
+ private const int MaxWordCount = AliasClientDb.Models.PasswordGeneratorDefaults.MaxWordCount;
/// <summary>
/// Default Diceware option values; an option button is highlighted when its value differs from the default.
diff --git a/apps/server/AliasVault.Client/Main/Models/PasswordSettings.cs b/apps/server/AliasVault.Client/Main/Models/PasswordSettings.cs
index c06091369..7cc35010d 100644
--- a/apps/server/AliasVault.Client/Main/Models/PasswordSettings.cs
+++ b/apps/server/AliasVault.Client/Main/Models/PasswordSettings.cs
@@ -8,6 +8,7 @@
namespace AliasVault.Client.Main.Models;
using System.Text.Json.Serialization;
+using AliasClientDb.Models;
/// <summary>
/// Settings for password generation.
@@ -18,7 +19,7 @@ public class PasswordSettings
/// Gets or sets the length of the password.
/// </summary>
[JsonPropertyName("Length")]
- public int Length { get; set; } = 18;
+ public int Length { get; set; } = PasswordGeneratorDefaults.DefaultPasswordLength;
/// <summary>
/// Gets or sets a value indicating whether to use lowercase letters.
@@ -60,7 +61,7 @@ public class PasswordSettings
/// Gets or sets the number of words in a Diceware passphrase.
/// </summary>
[JsonPropertyName("WordCount")]
- public int WordCount { get; set; } = 4;
+ public int WordCount { get; set; } = PasswordGeneratorDefaults.DefaultWordCount;
/// <summary>
/// Gets or sets the Diceware wordlist language. Unknown languages fall back to English in the Rust core.
diff --git a/apps/server/AliasVault.Client/Main/Utilities/PasswordLengthSlider.cs b/apps/server/AliasVault.Client/Main/Utilities/PasswordLengthSlider.cs
index d2e963500..470afa0fe 100644
--- a/apps/server/AliasVault.Client/Main/Utilities/PasswordLengthSlider.cs
+++ b/apps/server/AliasVault.Client/Main/Utilities/PasswordLengthSlider.cs
@@ -7,6 +7,8 @@
namespace AliasVault.Client.Main.Utilities;
+using AliasClientDb.Models;
+
/// <summary>
/// Utility functions for password length slider with non-linear scaling.
///
@@ -22,12 +24,12 @@ public static class PasswordLengthSlider
/// <summary>
/// Minimum password length.
/// </summary>
- public const int MinPasswordLength = 8;
+ public const int MinPasswordLength = PasswordGeneratorDefaults.MinPasswordLength;
/// <summary>
/// Maximum password length.
/// </summary>
- public const int MaxPasswordLength = 256;
+ public const int MaxPasswordLength = PasswordGeneratorDefaults.MaxPasswordLength;
/// <summary>
/// Slider minimum value (internal representation).
diff --git a/apps/server/Databases/AliasClientDb/Models/PasswordGeneratorDefaults.cs b/apps/server/Databases/AliasClientDb/Models/PasswordGeneratorDefaults.cs
new file mode 100644
index 000000000..cd5f765c6
--- /dev/null
+++ b/apps/server/Databases/AliasClientDb/Models/PasswordGeneratorDefaults.cs
@@ -0,0 +1,44 @@
+// <auto-generated />
+// This file is auto-generated from core/models/src/defaults/PasswordGeneratorDefaults.ts
+// Do not edit this file directly. Run 'core/models/build.sh' (or
+// 'node core/models/scripts/generate-password-defaults.cjs') to regenerate.
+
+#nullable enable
+
+namespace AliasClientDb.Models;
+
+/// <summary>
+/// Password generator defaults shared across all AliasVault clients.
+/// </summary>
+public static class PasswordGeneratorDefaults
+{
+ /// <summary>
+ /// Default length of a generated basic password.
+ /// </summary>
+ public const int DefaultPasswordLength = 18;
+
+ /// <summary>
+ /// Minimum password length offered by the UI length slider.
+ /// </summary>
+ public const int MinPasswordLength = 8;
+
+ /// <summary>
+ /// Maximum password length (also the hard cap enforced by the generator).
+ /// </summary>
+ public const int MaxPasswordLength = 256;
+
+ /// <summary>
+ /// Default number of words in a generated Diceware passphrase.
+ /// </summary>
+ public const int DefaultWordCount = 5;
+
+ /// <summary>
+ /// Minimum number of words offered by the UI word-count slider.
+ /// </summary>
+ public const int MinWordCount = 3;
+
+ /// <summary>
+ /// Maximum number of words (also the hard cap enforced by the generator).
+ /// </summary>
+ public const int MaxWordCount = 10;
+}
diff --git a/core/models/build.sh b/core/models/build.sh
index 28c39dea7..0f3bfb16c 100755
--- a/core/models/build.sh
+++ b/core/models/build.sh
@@ -20,8 +20,11 @@ echo ""
echo "πŸ”„ Generating platform-specific models (C#, Swift, Kotlin)..."
node scripts/generate-field-keys.cjs
+echo "πŸ”„ Generating password-generator defaults (Rust, C#)..."
+node scripts/generate-password-defaults.cjs
+
dist_path="dist"
-files_to_copy=("webapi" "vault" "metadata" "icons")
+files_to_copy=("webapi" "vault" "defaults" "metadata" "icons")
for target in "${TARGETS[@]}"; do
echo "πŸ“‚ Copying $package_name β†’ $target"
diff --git a/core/models/scripts/generate-password-defaults.cjs b/core/models/scripts/generate-password-defaults.cjs
new file mode 100644
index 000000000..7129f3245
--- /dev/null
+++ b/core/models/scripts/generate-password-defaults.cjs
@@ -0,0 +1,136 @@
+#!/usr/bin/env node
+/**
+ * Generates password-generator defaults constants for all cross-platform clients.
+ *
+ * Input: core/models/src/defaults/PasswordGeneratorDefaults.ts
+ * Outputs:
+ * - core/rust/src/password_generator/defaults.rs (Rust)
+ * - apps/server/Databases/AliasClientDb/Models/PasswordGeneratorDefaults.cs (C#)
+ *
+ * Note: Typescript clients can import the constants directly from the distributed `@/utils/dist/core/models/vault`.
+ */
+
+const fs = require('fs');
+const path = require('path');
+
+const REPO_ROOT = path.join(__dirname, '../../..');
+const TS_SOURCE = path.join(REPO_ROOT, 'core/models/src/defaults/PasswordGeneratorDefaults.ts');
+const TS_SOURCE_REL = 'core/models/src/defaults/PasswordGeneratorDefaults.ts';
+
+const RUST_OUTPUT = path.join(REPO_ROOT, 'core/rust/src/password_generator/defaults.rs');
+const CS_OUTPUT = path.join(REPO_ROOT, 'apps/server/Databases/AliasClientDb/Models/PasswordGeneratorDefaults.cs');
+
+/**
+ * Parse the `export const NAME = VALUE;` lines (each with its leading single-line
+ * JSDoc comment) out of the TypeScript source, preserving order.
+ */
+function parseConstants(source) {
+ const constants = [];
+ const lines = source.split('\n');
+ let pendingDoc = null;
+
+ for (const line of lines) {
+ const trimmed = line.trim();
+
+ // Single-line JSDoc comment: /** ... */
+ if (trimmed.startsWith('/**') && trimmed.endsWith('*/')) {
+ pendingDoc = trimmed.slice(3, -2).trim();
+ continue;
+ }
+
+ const constMatch = line.match(/^\s*export const ([A-Z0-9_]+)\s*=\s*(\d+)\s*;/);
+ if (constMatch) {
+ constants.push({
+ name: constMatch[1],
+ value: Number(constMatch[2]),
+ doc: pendingDoc || `${constMatch[1]}.`,
+ });
+ pendingDoc = null;
+ continue;
+ }
+
+ // Any other non-blank line resets a dangling doc comment.
+ if (line.trim() !== '') {
+ pendingDoc = null;
+ }
+ }
+
+ if (constants.length === 0) {
+ throw new Error(`No 'export const ... = <number>;' constants found in ${TS_SOURCE_REL}`);
+ }
+ return constants;
+}
+
+/** SCREAMING_SNAKE_CASE -> PascalCase (DEFAULT_PASSWORD_LENGTH -> DefaultPasswordLength). */
+function toPascalCase(name) {
+ return name
+ .toLowerCase()
+ .split('_')
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
+ .join('');
+}
+
+function generateRust(constants) {
+ const header = `//! Client-facing defaults for the password/passphrase generator.
+//!
+//! @generated β€” do NOT edit this file directly. It is generated from
+//! ${TS_SOURCE_REL} by core/models/scripts/generate-password-defaults.cjs.
+//! Edit the TypeScript source and run 'core/models/build.sh' to regenerate.
+`;
+
+ const body = constants
+ .map((c) => `/// ${c.doc}\npub const ${c.name}: u32 = ${c.value};`)
+ .join('\n\n');
+
+ return `${header}\n${body}\n`;
+}
+
+function generateCSharp(constants) {
+ const header = `// <auto-generated />
+// This file is auto-generated from ${TS_SOURCE_REL}
+// Do not edit this file directly. Run 'core/models/build.sh' (or
+// 'node core/models/scripts/generate-password-defaults.cjs') to regenerate.
+
+#nullable enable
+
+namespace AliasClientDb.Models;
+
+/// <summary>
+/// Password generator defaults shared across all AliasVault clients.
+/// </summary>
+public static class PasswordGeneratorDefaults
+{`;
+
+ const body = constants
+ .map((c) => {
+ const csName = toPascalCase(c.name);
+ return ` /// <summary>\n /// ${c.doc}\n /// </summary>\n public const int ${csName} = ${c.value};`;
+ })
+ .join('\n\n');
+
+ return `${header}\n${body}\n}\n`;
+}
+
+function writeIfChanged(filePath, contents) {
+ const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : null;
+ if (existing === contents) {
+ console.log(` βœ“ up to date: ${path.relative(REPO_ROOT, filePath)}`);
+ return;
+ }
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
+ fs.writeFileSync(filePath, contents);
+ console.log(` ✎ wrote: ${path.relative(REPO_ROOT, filePath)}`);
+}
+
+function main() {
+ const source = fs.readFileSync(TS_SOURCE, 'utf8');
+ const constants = parseConstants(source);
+
+ console.log(`Generating password-generator defaults from ${TS_SOURCE_REL}:`);
+ console.log(` ${constants.map((c) => `${c.name}=${c.value}`).join(', ')}`);
+
+ writeIfChanged(RUST_OUTPUT, generateRust(constants));
+ writeIfChanged(CS_OUTPUT, generateCSharp(constants));
+}
+
+main();
diff --git a/core/models/src/defaults/PasswordGeneratorDefaults.ts b/core/models/src/defaults/PasswordGeneratorDefaults.ts
new file mode 100644
index 000000000..ea1838db7
--- /dev/null
+++ b/core/models/src/defaults/PasswordGeneratorDefaults.ts
@@ -0,0 +1,28 @@
+/**
+ * Single source of truth for the password-length and Diceware word-count
+ * defaults and UI slider ranges shared across every AliasVault client.
+ *
+ * This file is distributed by core/models/build.sh to all platforms including:
+ * - `core/rust/src/password_generator/defaults.rs` (Rust core)
+ * - `apps/server/Databases/AliasClientDb/Models/PasswordGeneratorDefaults.cs` (C# web client)
+ *
+ * The TypeScript clients (browser extension, mobile app) import the constants directly from `@/utils/dist/core/models/defaults`.
+ */
+
+/** Default length of a generated basic password. */
+export const DEFAULT_PASSWORD_LENGTH = 18;
+
+/** Minimum password length offered by the UI length slider. */
+export const MIN_PASSWORD_LENGTH = 8;
+
+/** Maximum password length (also the hard cap enforced by the generator). */
+export const MAX_PASSWORD_LENGTH = 256;
+
+/** Default number of words in a generated Diceware passphrase. */
+export const DEFAULT_WORD_COUNT = 5;
+
+/** Minimum number of words offered by the UI word-count slider. */
+export const MIN_WORD_COUNT = 3;
+
+/** Maximum number of words (also the hard cap enforced by the generator). */
+export const MAX_WORD_COUNT = 10;
diff --git a/core/models/src/defaults/index.ts b/core/models/src/defaults/index.ts
new file mode 100644
index 000000000..d0b836519
--- /dev/null
+++ b/core/models/src/defaults/index.ts
@@ -0,0 +1,4 @@
+/**
+ * Export all shared cross-platform default/constant values.
+ */
+export * from './PasswordGeneratorDefaults';
diff --git a/core/models/src/vault/PasswordSettings.ts b/core/models/src/vault/PasswordSettings.ts
index dc17cd2f9..02cb557b8 100644
--- a/core/models/src/vault/PasswordSettings.ts
+++ b/core/models/src/vault/PasswordSettings.ts
@@ -61,7 +61,7 @@ export type PasswordSettings = {
Type?: PasswordGeneratorType;
/**
- * Number of words in the passphrase (diceware generator). Defaults to 4.
+ * Number of words in the passphrase (diceware generator).
*/
WordCount?: number;
diff --git a/core/rust/src/password_generator/defaults.rs b/core/rust/src/password_generator/defaults.rs
new file mode 100644
index 000000000..825afda7d
--- /dev/null
+++ b/core/rust/src/password_generator/defaults.rs
@@ -0,0 +1,23 @@
+//! Client-facing defaults for the password/passphrase generator.
+//!
+//! @generated β€” do NOT edit this file directly. It is generated from
+//! core/models/src/defaults/PasswordGeneratorDefaults.ts by core/models/scripts/generate-password-defaults.cjs.
+//! Edit the TypeScript source and run 'core/models/build.sh' to regenerate.
+
+/// Default length of a generated basic password.
+pub const DEFAULT_PASSWORD_LENGTH: u32 = 18;
+
+/// Minimum password length offered by the UI length slider.
+pub const MIN_PASSWORD_LENGTH: u32 = 8;
+
+/// Maximum password length (also the hard cap enforced by the generator).
+pub const MAX_PASSWORD_LENGTH: u32 = 256;
+
+/// Default number of words in a generated Diceware passphrase.
+pub const DEFAULT_WORD_COUNT: u32 = 5;
+
+/// Minimum number of words offered by the UI word-count slider.
+pub const MIN_WORD_COUNT: u32 = 3;
+
+/// Maximum number of words (also the hard cap enforced by the generator).
+pub const MAX_WORD_COUNT: u32 = 10;
diff --git a/core/rust/src/password_generator/mod.rs b/core/rust/src/password_generator/mod.rs
index 1012b8565..c7980e60a 100644
--- a/core/rust/src/password_generator/mod.rs
+++ b/core/rust/src/password_generator/mod.rs
@@ -10,6 +10,7 @@
//! - **Diceware** (`diceware`): a memorable passphrase built from a wordlist.
mod basic;
+pub mod defaults;
mod diceware;
mod wordlists;
@@ -143,20 +144,16 @@ pub struct PasswordSettings {
}
fn default_length() -> u32 {
- 18
+ defaults::DEFAULT_PASSWORD_LENGTH
}
fn default_word_count() -> u32 {
- 5
+ defaults::DEFAULT_WORD_COUNT
}
-/// Maximum values for the password and passphrase length. The apps cap passwords at 256
-/// characters and passphrases at 10 words; the core enforces the same so we prevent any
-/// excess length or word count to avoid potential issues.
-const MIN_PASSWORD_LENGTH: u32 = 1;
-const MAX_PASSWORD_LENGTH: u32 = 256;
-const MIN_WORD_COUNT: u32 = 1;
-const MAX_WORD_COUNT: u32 = 10;
+/// Minimum values for the password and passphrase length.
+const HARD_MIN_PASSWORD_LENGTH: u32 = 1;
+const HARD_MIN_WORD_COUNT: u32 = 1;
fn default_true() -> bool {
true
@@ -190,8 +187,10 @@ pub fn generate_from_settings(settings: &PasswordSettings) -> String {
let mut settings = settings.clone();
settings.length = settings
.length
- .clamp(MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH);
- settings.word_count = settings.word_count.clamp(MIN_WORD_COUNT, MAX_WORD_COUNT);
+ .clamp(HARD_MIN_PASSWORD_LENGTH, defaults::MAX_PASSWORD_LENGTH);
+ settings.word_count = settings
+ .word_count
+ .clamp(HARD_MIN_WORD_COUNT, defaults::MAX_WORD_COUNT);
match settings.generator_type {
GeneratorType::Basic => basic::generate(&settings, &mut rng),
diff --git a/core/rust/src/password_generator/tests.rs b/core/rust/src/password_generator/tests.rs
index 31811156c..7dfc30463 100644
--- a/core/rust/src/password_generator/tests.rs
+++ b/core/rust/src/password_generator/tests.rs
@@ -203,7 +203,7 @@ fn all_wordlists_have_7776_words() {
fn unknown_language_falls_back_to_english() {
// Case-insensitive match, and an unknown code must not error.
assert_eq!(wordlists::list("english"), wordlists::list("English"));
- assert_eq!(wordlists::list("Klingon"), wordlists::list("English"));
+ assert_eq!(wordlists::list("doesnotexist"), wordlists::list("English"));
let pw = generate_password(r#"{"Type":"diceware","Language":"Klingon"}"#).unwrap();
assert!(!pw.is_empty());
}