-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidation.py
More file actions
176 lines (144 loc) · 5.01 KB
/
Validation.py
File metadata and controls
176 lines (144 loc) · 5.01 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# # Get user input
# email = input("Enter your email: ")
# password = input("Enter your password: ")
# confirmation_password = input("Confirm your password: ")
# # Initialize flags
# has_at = False
# has_dot = False
# at_found = False
# last_dot_index = -1
# # Check email format manually
# i = 0
# while i < len(email):
# char = email[i]
# if char == '@':
# has_at = True
# at_found = True
# # Ensure there is at least one character before '@'
# if i == 0:
# has_at = False
# elif char == '.':
# if at_found:
# has_dot = True
# last_dot_index = i
# i += 1
# # Check domain part length after the last '.'
# domain_length_valid = False
# if has_at and has_dot and last_dot_index != -1:
# domain_part_length = len(email) - last_dot_index - 1
# if domain_part_length >= 2:
# domain_length_valid = True
# # Validate email and password
# if has_at and has_dot and domain_length_valid:
# # Check if password and confirmation password match
# if password == confirmation_password:
# print("User credentials are valid.")
# else:
# print("Passwords do not match.")
# else:
# print("Invalid email format.")
# # Allow up to 3 attempts
# attempts = 3
# valid_credentials = False
# while attempts > 0 and not valid_credentials:
# # Get user input
# email = input("Enter your email: ")
# password = input("Enter your password: ")
# confirmation_password = input("Confirm your password: ")
# # Initialize flags
# has_at = False
# has_dot = False
# at_found = False
# last_dot_index = -1
# # Check email format manually
# i = 0
# while i < len(email):
# char = email[i]
# if char == '@':
# has_at = True
# at_found = True
# # Ensure there is at least one character before '@'
# if i == 0:
# has_at = False
# elif char == '.':
# if at_found:
# has_dot = True
# last_dot_index = i
# i += 1
# # Check domain part length after the last '.'
# domain_length_valid = False
# if has_at and has_dot and last_dot_index != -1:
# domain_part_length = len(email) - last_dot_index - 1
# if domain_part_length >= 2:
# domain_length_valid = True
# # Validate email and password
# if has_at and has_dot and domain_length_valid and (password == confirmation_password):
# valid_credentials = True
# print("User credentials are valid.")
# else:
# attempts -= 1
# if attempts > 0:
# print(f"Invalid credentials. You have {attempts} attempt(s) left.")
# else:
# print("Failed to provide valid credentials after 3 attempts.")
# Maximum number of attempts
max_attempts = 3
# Get user input for email only once
email = input("Enter your email: ")
# Initialize flag for credential validity
valid_credentials = False
# Store the first password entered
first_password = None
# Initialize attempt counter
attempt = 0
# Loop for up to 3 attempts for password and confirmation password
while attempt < max_attempts:
# Get user input for password and confirmation password
password = input("Enter your password: ")
confirmation_password = input("Confirm your password: ")
# Initialize flags for email validation
has_at = False
has_dot = False
at_found = False
last_dot_index = -1
# Check email format manually
for i in range(len(email)):
char = email[i]
if char == '@':
has_at = True
at_found = True
# Ensure there is at least one character before '@'
if i == 0:
has_at = False
elif char == '.':
if at_found:
has_dot = True
last_dot_index = i
# Check domain part length after the last '.'
domain_length_valid = False
if has_at and has_dot and last_dot_index != -1:
domain_part_length = len(email) - last_dot_index - 1
if domain_part_length >= 2:
domain_length_valid = True
# Handle first password entry
if attempt == 0:
first_password = password
# Validate email and passwords
if has_at and has_dot and domain_length_valid and (password == confirmation_password):
if attempt > 0 and password != first_password:
print(f"Password does not match the first password.")
else:
valid_credentials = True
print("User credentials are valid.")
break
else:
attempts_left = max_attempts - (attempt + 1)
if attempts_left > 0:
print(f"Invalid credentials. You have {attempts_left} attempt(s) left.")
else:
print("Failed to provide valid credentials after 3 attempts.")
# Increment attempt counter
attempt += 1
# Post-loop action
if not valid_credentials:
print("Failed to provide valid credentials after 3 attempts.")