Skip to content

Commit

Permalink
Added function password_check in sonicprobe.helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Delle Cave committed Aug 8, 2022
1 parent 13a0ccf commit 0c815e5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
@@ -1,3 +1,9 @@
python-sonicprobe (0.3.46) unstable; urgency=medium

* Added function password_check in sonicprobe.helpers.

-- Adrien DELLE CAVE (Decryptus) <adc@doowan.net> Tue, 09 Aug 2022 00:15:00 +0200

python-sonicprobe (0.3.45) unstable; urgency=medium

* Fixed sonicprobe.helpers.to_yaml.
Expand Down
2 changes: 1 addition & 1 deletion RELEASE
@@ -1 +1 @@
0.3.45
0.3.46
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.3.45
0.3.46
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,4 +1,4 @@
httpdis>=0.6.22
httpdis>=0.6.23
pyOpenSSL
python-magic
psutil>=2.1
Expand Down
4 changes: 2 additions & 2 deletions setup.yml
Expand Up @@ -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:
Expand Down
42 changes: 42 additions & 0 deletions sonicprobe/helpers.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0c815e5

Please sign in to comment.