diff --git a/CHANGELOG b/CHANGELOG index df4c923..ed0bc55 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +python-sonicprobe (0.3.46) unstable; urgency=medium + + * Added function password_check in sonicprobe.helpers. + + -- Adrien DELLE CAVE (Decryptus) Tue, 09 Aug 2022 00:15:00 +0200 + python-sonicprobe (0.3.45) unstable; urgency=medium * Fixed sonicprobe.helpers.to_yaml. diff --git a/RELEASE b/RELEASE index 5d8b11a..b9c7814 100644 --- a/RELEASE +++ b/RELEASE @@ -1 +1 @@ -0.3.45 +0.3.46 diff --git a/VERSION b/VERSION index 5d8b11a..b9c7814 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.45 +0.3.46 diff --git a/requirements.txt b/requirements.txt index 7c071d1..9de53b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -httpdis>=0.6.22 +httpdis>=0.6.23 pyOpenSSL python-magic psutil>=2.1 diff --git a/setup.yml b/setup.yml index 42f1910..17f3ad2 100644 --- a/setup.yml +++ b/setup.yml @@ -4,8 +4,8 @@ description: sonicprobe author: Adrien Delle Cave author_email: pypi@doowan.net copyright: '2022 Adrien Delle Cave' -release: '0.3.45' -version: '0.3.45' +release: '0.3.46' +version: '0.3.46' license: License GPL-3 url: https://github.com/decryptus/sonicprobe python_requires: diff --git a/sonicprobe/helpers.py b/sonicprobe/helpers.py index 017b00d..d5336bc 100644 --- a/sonicprobe/helpers.py +++ b/sonicprobe/helpers.py @@ -56,11 +56,22 @@ ALPHANUM = frozenset( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") +PUNCT = frozenset(r'!"#$%&\'()*+, -./:;<=>?@[\]^_`{|}~') RE_CTRL_CHARS = re.compile(r'([\x00-\x1f\x7f-\x9f]+)') RE_SPACE_CHARS = re.compile(r'\s\s+') RE_YAML_QSTR = re.compile(r'^(?:\!\![a-z\/]+\s+)?\'(.*)\'$').match +PASSWD_MASK_DIGIT = 1 +PASSWD_MASK_UPPER = 2 +PASSWD_MASK_LOWER = 4 +PASSWD_MASK_PUNCT = 256 + +PASSWD_MASK_ALL = (PASSWD_MASK_DIGIT | + PASSWD_MASK_UPPER | + PASSWD_MASK_LOWER | + PASSWD_MASK_PUNCT) + def boolize(value): if isinstance(value, string_types): @@ -128,6 +139,37 @@ def normalize_string(value, case = None): clean_string( unicoder(value))) +def password_check(value, min_len = 6, max_len = 20, mask = PASSWD_MASK_ALL): + if not is_scalar(value): + return False + + v = ensure_text(value) + xlen = len(v) + + if xlen < min_len: + raise ValueError("length should be at least " + min_len) + + if xlen > max_len: + raise ValueError("length should be not be greater than " + max_len) + + if mask & PASSWD_MASK_DIGIT: + if not any(char.isdigit() for char in v): + raise ValueError("password should have at least one numeral") + + if mask & PASSWD_MASK_UPPER: + if not any(char.isupper() for char in v): + raise ValueError("password should have at least one uppercase letter") + + if mask & PASSWD_MASK_LOWER: + if not any(char.islower() for char in v): + raise ValueError("password should have at least one lowercase letter") + + if mask & PASSWD_MASK_PUNCT: + if not any(char in PUNCT for char in v): + raise ValueError("password should have at least one of punctuation") + + return True + def percent_to_float(value): if not isinstance(value, string_types): return False