diff options
| author | Bobby <[email protected]> | 2022-11-27 16:03:39 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-11-27 16:03:39 -0500 |
| commit | 1ed7e8bac832d4f8de8a320d581372038f7011d4 (patch) | |
| tree | 3ad342783ae289aaa5fcb6b86d424884e20495a1 /src | |
| parent | d02c725d5d5a6bbeb42cf703a4ac2116e2c45f2d (diff) | |
| download | edify-1ed7e8bac832d4f8de8a320d581372038f7011d4.tar.xz edify-1ed7e8bac832d4f8de8a320d581372038f7011d4.zip | |
added password validator
Diffstat (limited to 'src')
| -rw-r--r-- | src/edify/library/__init__.py | 1 | ||||
| -rw-r--r-- | src/edify/library/password.py | 30 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/edify/library/__init__.py b/src/edify/library/__init__.py index fe1f116..62d6528 100644 --- a/src/edify/library/__init__.py +++ b/src/edify/library/__init__.py @@ -12,3 +12,4 @@ from .url import url from .uuid import uuid from .zip import zip from .guid import guid +from .password import password diff --git a/src/edify/library/password.py b/src/edify/library/password.py new file mode 100644 index 0000000..85ef09c --- /dev/null +++ b/src/edify/library/password.py @@ -0,0 +1,30 @@ +import re + +def password(password: str, min_length: int = 8, max_length: int = 64, min_upper: int = 1, min_lower: int = 1, min_digit: int = 1, min_special: int = 1, special_chars: str = "!@#$%^&*()_+-=[]{}|;':\",./<>?") -> bool: + """Check if the given string is a valid password. + + Args: + password (str): The string to check. + min_length (int): The minimum length of the password. + max_length (int): The maximum length of the password. + min_upper (int): The minimum number of upper case characters. + min_lower (int): The minimum number of lower case characters. + min_digit (int): The minimum number of digits. + min_special (int): The minimum number of special characters. + special_chars (str): The special characters to check for. + + Returns: + bool: True if the string is a valid password, False otherwise. + """ + if len(password) < min_length or len(password) > max_length: + return False + + upper = re.findall("[A-Z]", password or "") + lower = re.findall("[a-z]", password or "") + digit = re.findall("[0-9]", password or "") + special = [c for c in password if c in special_chars] + + if len(upper) < min_upper or len(lower) < min_lower or len(digit) < min_digit or len(special) < min_special: + return False + + return True |
