-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
88 lines (66 loc) · 2.29 KB
/
Copy pathutils.py
File metadata and controls
88 lines (66 loc) · 2.29 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import re
import bcrypt
# from wtforms.validators import DataRequired,Length,Email,Regexp
import hmac
import hashlib
def hash_password(password):
salt = bcrypt.gensalt()
hashed_password = bcrypt.hashpw(password.encode(), salt)
print(hashed_password, "while signing in")
return hashed_password.decode()
def is_password_match(entered_password, stored_hash):
stored_hash_bytes = stored_hash.encode()
print(stored_hash_bytes, "hashed while log in hashed pass")
# print(entered_password.encode(), "actual password while logging in")
return bcrypt.checkpw(entered_password.encode(), stored_hash_bytes)
def is_strong_password(password):
min_length = 8
require_uppercase = True
require_lowercase = True
require_digit = True
require_special_char = True
if len(password) < min_length:
return False
if require_uppercase and not any(char.isupper() for char in password):
return False
if require_lowercase and not any(char.islower() for char in password):
return False
if require_digit and not any(char.isdigit() for char in password):
return False
if require_special_char and not re.search(r"[!@#$%^&*(),.?\":{}|<>]", password):
return False
return True
def valid_email(email):
email_regex = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
if not re.match(email_regex, email):
return False
return True
def valid_username(username):
min_len = 3
if len(username) < min_len:
return False
if re.search(r"[!@#$%^&*(),.?\":{}|<>]", username):
return False
return True
def valid_phone(phone):
ph_len = 11
ph_regex = r'^\d+$'
if len(phone) != ph_len:
return False
if not re.match(ph_regex, phone):
return False
return True
def is_valid_card_number(card_number):
if not card_number.isdigit() or not (13 <= len(card_number) <= 19):
return False
return True
def get_product_by_id(products_list, product_id):
for product in products_list:
if product['product_id'] == int(product_id):
return product
return None
def create_mac(price):
secret_key = b'supersecretkey'
price_bytes = str(price).encode('utf-8')
mac = hmac.new(secret_key, price_bytes, hashlib.sha256).hexdigest()
return mac