From d6a8a0ee01625814e647eb4cb7eb6c69825ff48f Mon Sep 17 00:00:00 2001 From: fspreck <f.spreckelsen@indiscale.com> Date: Fri, 10 Dec 2021 09:09:03 +0100 Subject: [PATCH] FIX: Add check for minimum password length --- src/caosdb/common/administration.py | 31 +++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/caosdb/common/administration.py b/src/caosdb/common/administration.py index 6870bbc2..cef0bd1c 100644 --- a/src/caosdb/common/administration.py +++ b/src/caosdb/common/administration.py @@ -59,7 +59,8 @@ def set_server_property(key, value): con._form_data_request(method="POST", path="_server_properties", params={key: value}).read() except EntityDoesNotExistError: - raise ServerConfigurationException("Debug mode in server is probably disabled.") from None + raise ServerConfigurationException( + "Debug mode in server is probably disabled.") from None def get_server_properties(): @@ -74,9 +75,11 @@ def get_server_properties(): """ con = get_connection() try: - body = con._http_request(method="GET", path="_server_properties").response + body = con._http_request( + method="GET", path="_server_properties").response except EntityDoesNotExistError: - raise ServerConfigurationException("Debug mode in server is probably disabled.") from None + raise ServerConfigurationException( + "Debug mode in server is probably disabled.") from None xml = etree.parse(body) props = dict() @@ -112,7 +115,27 @@ def get_server_property(key): def generate_password(length: int): - """ creates a random password that fulfills the security requirements """ + """Create a random password that fulfills the security requirements + + Parameters + ---------- + length : int + Length of the generated password. Has to be greater than 7. + + Returns + ------- + password : string + Generated random password of the given length + + Raises + ------ + ValueError: + If the length is less than 8. + """ + minimum_password_length = 8 + if length < minimum_password_length: + raise ValueError("CaosDB passwords have to be at least {} characters.".format( + minimum_password_length)) sample_letters = string.ascii_letters + string.digits + "!#$%*+-/:;?_" password = ''.join((random.choice(sample_letters) for i in range(length))) -- GitLab