add special characters functionnality to random password generator function make_password

This commit is contained in:
rdzantoine.pro@gmail.com
2025-06-23 10:03:06 +02:00
committed by Antoine Nguyen
parent c2a775b9ad
commit f2697b6c92
+6 -3
View File
@@ -293,10 +293,13 @@ def domain_has_authorized_mx(name):
def make_password():
"""Create a random password."""
length = int(param_tools.get_global_parameter("random_password_length", app="core"))
while True:
allow_special_characters = bool(param_tools.get_global_parameter("allow_special_characters", app="core"))
possible_chars = string.ascii_letters + string.digits
for i in range(10): # limit tries
if allow_special_characters: # add special characters in random passwd
possible_chars += string.punctuation
password = "".join(
random.SystemRandom().choice(string.ascii_letters + string.digits)
for _ in range(length)
random.SystemRandom().choice(possible_chars) for _ in range(length)
)
try:
password_validation.validate_password(password)