-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation_backend.py
More file actions
70 lines (56 loc) · 2.29 KB
/
validation_backend.py
File metadata and controls
70 lines (56 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
import re
class FormValidator:
def __init__(self, data):
self.data = data
self.errors = {}
def validate(self):
pass
def is_valid(self):
self.validate()
return not bool(self.errors)
class UserNameValidator(FormValidator):
def validate(self):
username = self.data["username"]
if not username:
self.errors["username"] = "Username is required"
elif len(username) < 6:
self.errors["username"] = "Username must be at least 6 characters"
class SecretKeyValidator(FormValidator):
def validate(self):
secret_key = self.data.get("secret_key")
if not secret_key:
self.errors["secret_key"] = "Generate a QRCode Before You Scan"
class PasswordValidator(FormValidator):
def validate(self):
password = self.data.get("password")
if not password:
self.errors["password"] = "Password is required"
elif len(password) < 8:
self.errors["password"] = "Password must be at least 8 characters"
elif not re.search(r"[A-Z]", password):
self.errors[
"password"
] = "Password must contain at least one uppercase letter"
elif not re.search(r"[a-z]", password):
self.errors[
"password"
] = "Password must contain at least one lowercase letter"
elif not re.search(r"\d", password):
self.errors["password"] = "Password must contain at least one integer"
elif not re.search(r"[!@#$%^&*_]", password):
self.errors[
"password"
] = "Password must contain at least one special character"
class ConfirmPasswordValidator(FormValidator):
def validate(self):
password = self.data.get("password")
confirm_password = self.data.get("confirm_password")
if not confirm_password:
self.errors["confirm_password"] = "Confirm password is required"
elif password != confirm_password:
self.errors["confirm_password"] = "Passwords do not match"
class TwoFactorValidator(FormValidator):
def validate(self):
two_factor_code = self.data.get("two_factor_code")
if not two_factor_code:
self.errors["two_factor_code"] = "Enter Two Factor Code"