Skip to content

Commit 73e7c9d

Browse files
committed
šŸ”’(backend) respect keycloak password policy when generating passwords
1 parent 7a0f6fb commit 73e7c9d

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

ā€Žsrc/backend/core/services/identity/keycloak.pyā€Ž

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,27 @@ def resync_all_mailboxes_to_keycloak():
307307

308308

309309
def generate_password(length=12):
310-
"""Generate a secure random password with at least one uppercase, one lowercase, and one digit."""
311-
if length < 3:
310+
"""Generate a secure random password with at least one uppercase, one lowercase, one digit, and one special character."""
311+
if length < 12:
312312
raise ValueError(
313-
"Password length must be at least 3 to satisfy all requirements."
313+
"Password length must be at least 12 to satisfy all requirements."
314314
)
315315

316316
_upper = "ABCDEFGHJKLMNPQRTUVWXYZ"
317317
_lower = "abcdefghijkmnopqrstuvwxyz"
318318
_digits = "2346789"
319+
_special = "!@#$%&*?"
319320

320321
# Ensure at least one of each required character type
321322
password_chars = [
322323
secrets.choice(_upper),
323324
secrets.choice(_lower),
324325
secrets.choice(_digits),
326+
secrets.choice(_special),
325327
]
326328
# Fill the rest of the password length with random choices
327329
password_chars += [
328-
secrets.choice(_upper + _lower + _digits) for _ in range(length - 3)
330+
secrets.choice(_upper + _lower + _digits + _special) for _ in range(length - 4)
329331
]
330332
# Shuffle to avoid predictable positions
331333
secrets.SystemRandom().shuffle(password_chars)

0 commit comments

Comments
Ā (0)
⚔