Skip to content

Modern Docker Management, Designed for Everyone

fix: align first-login password validation with configured policy

Kyle Mendellb71892d09024
diff --git a/AGENTS.md b/AGENTS.md
index 71ee2a4c6..489de3ade 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -17,6 +17,8 @@ headless agent modes, and a Cobra CLI.
- Updating in place allows moving related logic into focused sibling files within the
same domain. Split by responsibility, not a fixed line count. Avoid trivial file
splits, unnecessary abstractions, and unrelated restructuring.
+- Avoid nested or chained ternary expressions unless absolutely necessary. Prefer
+ `if`/`else` or `switch` blocks for conditional logic with multiple branches.
- Keep comments short. If code needs a paragraph to explain its structure, simplify it.
- Never run state-changing Git commands. Do not stage, commit, push, tag, stash,
create branches, or create worktrees.
diff --git a/frontend/src/lib/components/dialogs/first-login-password-dialog.svelte b/frontend/src/lib/components/dialogs/first-login-password-dialog.svelte
index 334687fc6..f7df54710 100644
--- a/frontend/src/lib/components/dialogs/first-login-password-dialog.svelte
+++ b/frontend/src/lib/components/dialogs/first-login-password-dialog.svelte
@@ -5,10 +5,12 @@
import { ArcaneButton } from '#lib/components/arcane-button/index.js';
import { Label } from '#lib/components/ui/label/index.js';
import { authService } from '#lib/services/auth-service.js';
+ import settingsStore from '#lib/stores/config-store.svelte.js';
import { toast } from 'svelte-sonner';
import { EyeOnIcon, EyeOffIcon, AlertIcon } from '#lib/icons/index.js';
import { m } from '#lib/paraglide/messages.js';
import { createMutation } from '@tanstack/svelte-query';
+ import { z } from 'zod/v4';
let {
open = $bindable(false),
@@ -26,7 +28,47 @@
let showNewPassword = $state(false);
let showConfirmPassword = $state(false);
- const isValid = $derived(currentPassword.length > 0 && [...newPassword].length >= 8 && confirmPassword === newPassword);
+ const passwordPolicy = $derived.by(() => {
+ const requiredCharacters = /(?=.*\p{Lu})(?=.*\p{Ll})(?=.*\p{Nd})/su;
+
+ switch (settingsStore.current?.authPasswordPolicy) {
+ case 'basic': {
+ const requirements = m.security_password_policy_basic_tooltip();
+ return { schema: z.string().min(8, requirements), requirements };
+ }
+ case 'standard': {
+ const requirements = m.security_password_policy_standard_tooltip();
+ return {
+ schema: z.string().min(10, requirements).regex(requiredCharacters, requirements),
+ requirements
+ };
+ }
+ default: {
+ const requirements = m.security_password_policy_strong_tooltip();
+ return {
+ schema: z
+ .string()
+ .min(12, requirements)
+ .regex(requiredCharacters, requirements)
+ .regex(/[\p{P}\p{S}\p{White_Space}]/u, requirements),
+ requirements
+ };
+ }
+ }
+ });
+ const formSchema = $derived(
+ z
+ .object({
+ currentPassword: z.string().min(1, m.common_required()),
+ newPassword: passwordPolicy.schema,
+ confirmPassword: z.string()
+ })
+ .refine((data) => data.newPassword === data.confirmPassword, {
+ message: m.first_login_error_mismatch(),
+ path: ['confirmPassword']
+ })
+ );
+ const validation = $derived(formSchema.safeParse({ currentPassword, newPassword, confirmPassword }));
const changePasswordMutation = createMutation(() => ({
mutationFn: ({ currentPassword, newPassword }: { currentPassword: string; newPassword: string }) =>
authService.changePassword(currentPassword, newPassword),
@@ -43,17 +85,13 @@
const isLoading = $derived(changePasswordMutation.isPending);
function handleSubmit() {
- if (!isValid) {
- if ([...newPassword].length < 8) {
- error = m.first_login_error_length();
- } else if (confirmPassword !== newPassword) {
- error = m.first_login_error_mismatch();
- }
+ if (!validation.success) {
+ error = validation.error.issues[0]?.message ?? m.first_login_error_failed();
return;
}
error = '';
- changePasswordMutation.mutate({ currentPassword, newPassword });
+ changePasswordMutation.mutate(validation.data);
}
</script>
@@ -115,7 +153,8 @@
id="new-password"
type={showNewPassword ? 'text' : 'password'}
bind:value={newPassword}
- placeholder={m.first_login_new_password_placeholder()}
+ placeholder={m.users_password_enter()}
+ aria-describedby="new-password-requirements"
required
disabled={isLoading}
/>
@@ -137,6 +176,8 @@
</InputGroup.Root>
</div>
+ <p id="new-password-requirements" class="text-sm text-muted-foreground">{passwordPolicy.requirements}</p>
+
<div class="space-y-2">
<Label for="confirm-password">{m.first_login_confirm_password()}</Label>
<InputGroup.Root>
@@ -171,7 +212,7 @@
<ArcaneButton
type="submit"
onclick={handleSubmit}
- disabled={!isValid || isLoading}
+ disabled={!validation.success || isLoading}
loading={isLoading}
action="confirm"
customLabel={m.first_login_submit()}
diff --git a/tests/utils/auth.util.ts b/tests/utils/auth.util.ts
index 61fa46e42..813db8e51 100644
--- a/tests/utils/auth.util.ts
+++ b/tests/utils/auth.util.ts
@@ -38,25 +38,27 @@ async function changeDefaultPassword(page: Page, currentPassword: string, newPas
await dialog.getByRole('textbox', { name: 'Current Password' }).fill(currentPassword);
await dialog.getByRole('textbox', { name: 'New Password', exact: true }).fill('abcdefgh');
await dialog.getByRole('textbox', { name: 'Confirm New Password' }).fill('abcdefgh');
- const policyResponsePromise = page.waitForResponse(
- (response) =>
- response.status() === 400 &&
- response.request().method() === 'POST' &&
- new URL(response.url()).pathname === '/api/auth/password'
- );
- await dialog.getByRole('button', { name: 'Change Password' }).click();
- const policyResponse = await policyResponsePromise;
+ const submitButton = dialog.getByRole('button', { name: 'Change Password' });
+ await expect(submitButton).toBeDisabled();
+ await dialog.getByRole('textbox', { name: 'New Password', exact: true }).fill('abcdefghijkl');
+ await dialog.getByRole('textbox', { name: 'Confirm New Password' }).fill('abcdefghijkl');
+ await expect(submitButton).toBeDisabled();
+ const policyResponse = await page.request.post('/api/auth/password', {
+ data: { currentPassword, newPassword: 'abcdefghijkl' }
+ });
+ expect(policyResponse.status()).toBe(400);
expect(await policyResponse.json()).toMatchObject({
status: 400,
type: 'urn:arcane:problem:password-policy:strong'
});
await expect(
- page.getByText('12+ chars with upper, lower, number, and symbol.', { exact: true })
+ dialog.getByText('12+ chars with upper, lower, number, and symbol.', { exact: true })
).toBeVisible();
await dialog.getByRole('textbox', { name: 'New Password', exact: true }).fill(newPassword);
await dialog.getByRole('textbox', { name: 'Confirm New Password' }).fill(newPassword);
- await dialog.getByRole('button', { name: 'Change Password' }).click();
+ await expect(submitButton).toBeEnabled();
+ await submitButton.click();
await page
.getByRole('listitem')
.filter({ hasText: 'Password changed successfully' })