fix(android): new passwords follow the web's rules and wording (DRY B5)

Settings › Password said "New passwords do not match." where the web
says "Passwords do not match.", and neither it nor an admin resetting
someone's password checked the 8-character minimum before sending: the
reset button lit up after one character. auth/PasswordRules mirrors
web/src/lib/auth/password.ts: the minimum, the "At least 8
characters." hint under the field, the too-short and mismatch wording.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 14:09:48 -05:00
co-authored by Claude Opus 5.5
parent c45be1720a
commit 25cee5ed69
5 changed files with 74 additions and 2 deletions
@@ -31,6 +31,7 @@ import androidx.compose.material3.TextButton
import android.content.ClipData
import androidx.compose.ui.platform.ClipEntry
import androidx.compose.ui.platform.LocalClipboard
import com.fabledsword.minstrel.auth.PasswordRules
import com.fabledsword.minstrel.models.Invite
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@@ -471,6 +472,7 @@ private fun ResetPasswordDialog(
value = newPassword,
onValueChange = { newPassword = it },
label = { Text("New password") },
supportingText = { Text(PasswordRules.HINT) },
singleLine = true,
visualTransformation = PasswordVisualTransformation(),
)
@@ -479,7 +481,7 @@ private fun ResetPasswordDialog(
confirmButton = {
TextButton(
onClick = { onConfirm(newPassword) },
enabled = newPassword.isNotEmpty(),
enabled = PasswordRules.isLongEnough(newPassword),
) { Text("Reset") }
},
dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },
@@ -0,0 +1,22 @@
package com.fabledsword.minstrel.auth
/**
* The rules every new-password field shares (Settings › Password, an admin
* resetting someone's password), worded as the web app words them
* (web/src/lib/auth/password.ts). The server enforces the same minimum and
* answers password_too_short; checking here only saves the round trip.
*/
object PasswordRules {
const val MIN_LENGTH = 8
/** The hint under a new-password field. */
const val HINT = "At least $MIN_LENGTH characters."
/** Said when a new password is shorter than [MIN_LENGTH]. */
const val TOO_SHORT = "Password must be at least $MIN_LENGTH characters."
/** Said when a password and its confirmation differ. */
const val DIFFER = "Passwords do not match."
fun isLongEnough(password: String): Boolean = password.length >= MIN_LENGTH
}
@@ -19,6 +19,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.fabledsword.minstrel.auth.PasswordRules
import com.fabledsword.minstrel.theme.Muted
import com.fabledsword.minstrel.theme.Section
import com.fabledsword.minstrel.theme.SwitchRow
@@ -36,6 +37,7 @@ fun PasswordCard(viewModel: PasswordViewModel = hiltViewModel()) {
value = state.next,
label = "New password",
onChange = viewModel::setNext,
hint = PasswordRules.HINT,
)
PasswordField(
value = state.confirm,
@@ -73,11 +75,13 @@ private fun PasswordField(
value: String,
label: String,
onChange: (String) -> Unit,
hint: String? = null,
) {
OutlinedTextField(
value = value,
onValueChange = onChange,
label = { Text(label) },
supportingText = hint?.let { { Text(it) } },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
visualTransformation = PasswordVisualTransformation(),
@@ -3,6 +3,7 @@ package com.fabledsword.minstrel.settings.ui
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.fabledsword.minstrel.api.ErrorCopy
import com.fabledsword.minstrel.auth.PasswordRules
import com.fabledsword.minstrel.settings.data.MeRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
@@ -46,7 +47,8 @@ class PasswordViewModel @Inject constructor(
val validationError: String? = when {
s.isChanging -> "" // sentinel: silent no-op
s.current.isEmpty() || s.next.isEmpty() -> "All fields required."
s.next != s.confirm -> "New passwords do not match."
!PasswordRules.isLongEnough(s.next) -> PasswordRules.TOO_SHORT
s.next != s.confirm -> PasswordRules.DIFFER
else -> null
}
if (validationError != null) {