Files
max/max/auth/password_policy.py
T
finnandClaude Opus 5.5 e88704017e Raise the minimum password length to 20 characters
The initial admin password of setup-prod-initial-login is now
admin-initial-password.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 19:23:37 +00:00

28 lines
963 B
Python

from .hashing import MAX_PASSWORD_BYTES, is_password_too_long
MIN_PASSWORD_LENGTH = 20
PASSWORD_TOO_SHORT_MESSAGE = (
"The password must be at least {min_length} characters long"
)
PASSWORD_TOO_LONG_MESSAGE = (
"The password must be at most {max_bytes} bytes long "
"({max_bytes} characters, fewer with umlauts or special characters)"
)
# Fills the placeholders of the messages, e.g. t(error, **PASSWORD_MESSAGE_ARGUMENTS)
PASSWORD_MESSAGE_ARGUMENTS = dict(
min_length=MIN_PASSWORD_LENGTH, max_bytes=MAX_PASSWORD_BYTES
)
def validate_password(password: str, min_length=MIN_PASSWORD_LENGTH):
"""
Checks a new password. Returns the (untranslated) error message, or None if the
password is valid. Existing passwords are not checked against this policy.
"""
if len(password) < min_length:
return PASSWORD_TOO_SHORT_MESSAGE
if is_password_too_long(password):
return PASSWORD_TOO_LONG_MESSAGE
return None