-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsertData.py
238 lines (203 loc) · 6.89 KB
/
InsertData.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import CreateConnection
import re
from phonenumbers import carrier
from phonenumbers.phonenumberutil import number_type
from datetime import datetime
from datetime import date, timedelta
def insert():
# First Name
dummy = True
fname = ""
while(dummy):
fname = input("First Name : ")
if(fname==''):
print("Please Write Your First Name")
elif fname.replace(" ", "").isalpha():
dummy = False
else:
print("First Name Invalid Please Provide Valid First Name")
# Last Name
dummy = True
lname = ""
while(dummy):
lname = input("Last Name : ")
if(lname==''):
print("Please Write Your Last Name")
elif lname.replace(" ", "").isalpha():
dummy = False
else:
print ("Last Name Invalid Please Provide Valid Last Name")
# # Mobile Number
dummy = True
mobile = ""
while(dummy):
mobile = input("Mobile Number : ")
if(mobile_verification(mobile)):
dummy = False
else:
print("Wrong Mobile Number Please Provide Valid Mobile Number")
# Email
dummy = True
email = ""
while(dummy):
email = input("Email : ")
if(email_verification(email)):
dummy = False
else:
print("Wrong Email Please Provide Valid Email")
# Password
dummy = True
password = ""
while(dummy):
password = input("Password : ")
if(password==''):
print("Please Write your Password")
dummy = True
elif(password_check(password)):
encrypt_password = argon2_algo(password)
dummy = False
else:
dummy = True
# Address
dummy = True
address = ""
while(dummy):
address = input("Address : ")
if(address==''):
dummy = False
elif address.replace(" ", "").isalpha():
dummy = False
else:
print ("Address Invalid Please Provide Valid Address")
# City
dummy = True
city = ""
while(dummy):
city = input("City : ")
if(city==''):
dummy = False
elif city.replace(" ", "").isalpha():
dummy = False
else:
print ("City Invalid Please Provide Valid City")
# State
dummy = True
state = ""
while(dummy):
state = input("State : ")
if(state==''):
dummy = False
elif state.replace(" ", "").isalpha():
dummy = False
else:
print ("State Invalid Please Provide Valid State")
# Country
dummy = True
country = ""
while(dummy):
country = input("Country : ")
if(country==''):
dummy = False
elif country.replace(" ", "").isalpha():
dummy = False
else:
print ("Country Invalid Please Provide Valid Country")
# PinCode
dummy = True
pin_code = ""
while(dummy):
pin_code = input("PinCode : ")
if(pin_code == ""):
dummy = False
if(pincode_verification(pin_code)):
dummy = False
else:
print("Wrong Pin Code Please Provide Valid Pin Code")
# DateOfBirth
dummy = True
dob = ""
while(dummy):
dob = input("Enter your date of birth in the format DD/MM/YYYY : ")
if(is_valid_dob(dob)):
dummy = False
else:
print("Incorrect DOB!")
dummy = True
# Query
Query = "INSERT INTO user_details(first_name,last_name,mobile_number,email_id,password,address,city,state,country,pin_code,date_of_birth) VALUES('{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}');".format(fname,lname,mobile,email,encrypt_password,address,city,state,country,pin_code,dob)
try:
CreateConnection.cursor.execute(Query)
CreateConnection.db.commit()
print("Successful")
except Exception as e:
print(e)
# ========================================================================================================== #
# Email Verification
def email_verification(email):
pat = "^[a-zA-Z0-9.+]+@[a-zA-Z0-9]+\.(com|co\.in|[a-zA-Z]+)$"
if(email==''):
return False
elif re.match(pat,email):
return True
return False
# ========================================================================================================== #
# Phone Number Verification
def mobile_verification(mobile):
if(mobile==''):
return False
elif(re.match(r"^(\+91[-\s]?)?[0]?[6789]\d{9}$", mobile)):
return True
return False
# ========================================================================================================== #
def pincode_verification(pin_code):
if(pin_code==''):
return False
elif(re.fullmatch("\d{4}|\d{6}", pin_code)):
return True
return False
# ========================================================================================================== #
def argon2_algo(password):
from argon2 import PasswordHasher
ph = PasswordHasher()
hash = ph.hash(password)
return hash
# ==========================================================================================================
def is_valid_dob(dob_str):
# convert the string to a date object
try:
dob = datetime.strptime(dob_str, "%d/%m/%Y").date()
except ValueError:
print("Incorrect date format, should be DD/MM/YYYY")
return False
# check if the date is in the past
if dob >= date.today():
print("Date of birth should be in the past")
return False
# check if the date is not more than 150 years ago
if dob <= date.today() - timedelta(days=365.25 * 150):
print("Age should not be greater than 150 years")
return False
return True
# ==========================================================================================================
def password_check(password):
# check length of password
if len(password) < 8:
return False
# check if password has at least one digit
if not any(char.isdigit() for char in password):
return False
# check if password has at least one lowercase letter
if not any(char.islower() for char in password):
return False
# check if password has at least one uppercase letter
if not any(char.isupper() for char in password):
return False
# check if password has at least one special character
special_characters = "!@#$%^&*()_+-=[]{};:,.<>/?`~"
if not any(char in special_characters for char in password):
return False
# if all conditions are met, return True
return True
# ==========================================================================================================
insert()
# ==========================================================================================================