From 243071d4cc44b06c7e8bfcecf6b8c0809443fe53 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Mon, 2 Jun 2025 12:26:28 +0800 Subject: [PATCH] Added ValidatePasswordStrength in Utilities.py --- src/modules/Utilities.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/modules/Utilities.py b/src/modules/Utilities.py index 106579a..f524eb2 100644 --- a/src/modules/Utilities.py +++ b/src/modules/Utilities.py @@ -73,4 +73,23 @@ def GenerateWireguardPrivateKey() -> tuple[bool, str] | tuple[bool, None]: stderr=subprocess.STDOUT) return True, publicKey.decode().strip('\n') except subprocess.CalledProcessError: - return False, None \ No newline at end of file + return False, None + +def ValidatePasswordStrength(password: str) -> tuple[bool, str] | tuple[bool, None]: + # Rules: + # - Must be over 8 characters & numbers + # - Must contain at least 1 Uppercase & Lowercase letters + # - Must contain at least 1 Numbers (0-9) + # - Must contain at least 1 special characters from $&+,:;=?@#|'<>.-^*()%!~_- + if len(password) < 8: + return False, "Password must be 8 characters or more" + if not re.search(r'[a-z]', password): + return False, "Password must contain at least 1 lowercase character" + if not re.search(r'[A-Z]', password): + return False, "Password must contain at least 1 uppercase character" + if not re.search(r'\d', password): + return False, "Password must contain at least 1 number" + if not re.search(r'[$&+,:;=?@#|\'<>.\-^*()%!~_-]', password): + return False, "Password must contain at least 1 special character from $&+,:;=?@#|'<>.-^*()%!~_-" + + return True, None \ No newline at end of file