-
Notifications
You must be signed in to change notification settings - Fork 0
/
_pass.py
62 lines (50 loc) · 1.79 KB
/
_pass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from hashlib import sha512
from re import compile, findall, match
hash = lambda x: sha512(str(x).encode("utf-8")).hexdigest()
def encrypt_password(password: str) -> str:
"""Returns Password Hashed with sha512 algo"""
return hash(password)
def check_password(stored: str, entered: str) -> bool:
"""Verfies Hashed Password with password in db"""
return stored == entered
class Validator(object):
name_pattern = compile("[A-Za-z]")
id_pattern = compile("[a-z0-9@_$-]")
pwd_pattern = compile("[A-za-z0-9@_]")
@staticmethod
def validate_name(name: str) -> bool:
"""Validate name passed in to store"""
if findall(Validator.name_pattern, name) == list(name):
return True
else:
return False
@staticmethod
def validate_id(uid: str) -> bool:
"""Validate user id"""
if not findall("[a-z]", uid):
return False
elif not findall("[0-9]", uid):
return False
elif not findall("[@_$-]", uid):
return False
elif findall(Validator.id_pattern, uid) != list(uid):
return False
return True
@staticmethod
def validate_pwd(pwd: str) -> bool:
"""Validate password passed"""
if not findall("[A-Z]", pwd):
return False
elif not findall("[a-z]", pwd):
return False
elif not findall("[0-9]", pwd):
return False
elif not findall("[@_]", pwd):
return False
elif findall(Validator.pwd_pattern, pwd) != list(pwd):
return False
return True
if __name__ == "__main__":
print(Validator.validate_name("Aniruddh")) # True
print(Validator.validate_id("aniruddh@07")) # True
print(Validator.validate_pwd("Aniruddh@07")) # True