Shuffle/app/lib/features/auth/domain/validation/password_policy.dart
cschlaefke 54337ffc59 feat(auth): add auth domain, repository, validators and router redirects
Refs #1

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 00:09:47 +01:00

38 lines
1.3 KiB
Dart

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:shuffle/features/auth/domain/validation/common_passwords.dart';
part 'password_policy.freezed.dart';
/// Fehler der Passwortregel.
@freezed
sealed class PasswordError with _$PasswordError {
/// Zu kurz; [missing] Zeichen fehlen noch.
const factory PasswordError.tooShort(int missing) = PasswordTooShort;
const factory PasswordError.common() = PasswordCommon;
}
/// Passwortregel (KTO-01 Kriterium 3): mindestens 10 Zeichen und nicht auf der
/// Liste häufiger Passwörter.
///
/// Die Länge zählt Unicode-Codepoints des unveränderten Passworts (Leerzeichen
/// sind gültige Zeichen und werden nicht entfernt). Nur der Listenvergleich
/// trimmt und ignoriert die Groß-/Kleinschreibung.
abstract final class PasswordPolicy {
static const minLength = 10;
/// Prüft [password]. Ist die Liste noch nicht geladen ([common] `null`),
/// läuft nur die Längenprüfung; vor dem Absenden mit Liste erneut prüfen.
static PasswordError? validate(
String password, {
CommonPasswordList? common,
}) {
final length = password.runes.length;
if (length < minLength) {
return PasswordError.tooShort(minLength - length);
}
if (common != null && common.contains(password)) {
return const PasswordError.common();
}
return null;
}
}