From 6005b76b7e5cf48787b10ae106ce360588f9516b Mon Sep 17 00:00:00 2001 From: Eric Costa Date: Thu, 5 Dec 2024 19:36:32 -0300 Subject: [PATCH] feat: enhance password generation for Keycloak user creation --- connect/usecases/users/create.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/connect/usecases/users/create.py b/connect/usecases/users/create.py index 05878b9b..5199fc9f 100644 --- a/connect/usecases/users/create.py +++ b/connect/usecases/users/create.py @@ -19,7 +19,24 @@ class CreateKeycloakUserUseCase: user_dto: KeycloakUserDTO def generate_password(self) -> str: - return "".join(random.choices(string.ascii_letters + string.digits, k=10)) + uppercase = string.ascii_uppercase + lowercase = string.ascii_lowercase + digits = string.digits + special = "!@#$%^&*()_+-=[]{}|;:,.<>?" + + password = [ + random.choice(uppercase), # 1 uppercase + random.choice(lowercase), # 1 lowercase + random.choice(digits), # 1 digit + random.choice(special), # 1 special + ] + + all_chars = uppercase + lowercase + digits + special + password.extend(random.choices(all_chars, k=4)) + + random.shuffle(password) + + return "".join(password) def execute(self) -> dict: try: