-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
156 lines (136 loc) · 5.22 KB
/
main.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
# Login and Register System using Python
import re
import os
# Class for verification of Username
class Username:
def __init__(self, new_username=" "):
self.new_username = new_username
def validation(self, new_username=" "):
# Username verification conditions
if re.search("^[0-9]", new_username):
print("Username shouldn't start with Numerical digit.")
return
if re.search("^[!@#$%^&*]", new_username):
print("Username shouldn't start with special character.")
return
if re.search("[A-Z]", new_username):
print("Username shouldn't have uppercase letter.")
return
if not re.search("[a-z0-9]{2,20}@[a-z]{2,10}[.][a-z]{2,4}", new_username):
return
return True
# Class for verification of Password
class Password:
def __init__(self, new_password=" "):
self.new_password = new_password
def verify(self, new_password=" "):
# Password Verification Conditions
if not re.search("[A-Z]", new_password):
print("Password must have 1Uppercase character")
return
if not re.search("[a-z]", new_password):
print("Password must have 1 Lowercase character")
return
if not re.search("[0-9]", new_password):
print("Password must have 1 Numerical character")
return
if not 16 >= len(new_password) > 5:
print("Password must have 5 to 16 characters")
return
if not re.search(r'[@#!$%^&*|;:_]', new_password):
print("Password must contain 1 special character")
return
return True
# user have to select they want to Login/Register
userchoice = input("Please choose Login / Register: ")
new_username = "notvalid"
new_password = "notvalid"
corrected_password = "notvalid"
File = open("Credentials.txt", "a")
# Login Part - if user chooses login
if userchoice == "Login":
username = input("Username: ")
password = input("Password: ")
# This part checks if the username and password entered are valid
File = open("Credentials.txt", "r")
lines = File.readlines()
File.close()
for itr in lines:
temp = itr.split()
if username and password in temp:
print("User Validated")
break
else:
print("Invalid Credentials.Type 'O' to retrieve your old password or 'N' to enter new password.")
# Here, user can Retrieve their old password or reset with new password
A = input()
# Old Password Retrieving Part
if A == "O":
reenter_username = input("Username: ")
for itr in lines:
temp = itr.split()
if reenter_username in temp:
p = temp[1:]
print("Your Password is:", *p)
break
else:
print("User not registered! Go to Registration.")
# Overwriting Existing Password part
elif A == "N":
reenter_username = input("Username: ")
File1 = open("Credentials.txt", "r")
lines = File1.readlines()
for itr in lines:
temp = itr.split()
Temp_File = open("Temp_File.txt", "a")
if len(lines) > 0:
if temp[0] == reenter_username:
for x in corrected_password:
corrected_password = input("Please, Enter New Password: ")
cor = Password()
if cor.verify(corrected_password):
Temp_File.write(reenter_username+" "+corrected_password+"\n")
print("Password updated Successfully.")
break
else:
Temp_File.writelines(temp[0]+" "+temp[1])
Temp_File.write("\n")
File1.close()
Temp_File.close()
os.remove("Credentials.txt")
os.rename("Temp_File.txt", "Credentials.txt")
else:
print("User not found, please go to Registration.")
File.close()
# Registration part - If user chooses Registration
elif userchoice == "Register":
for x in new_username:
new_username = input("E-Mail id: ")
# This part verifies the username with the help of class Username
c = Username()
if c.validation(new_username):
File = open("Credentials.txt", "r")
lines = File.readlines()
File.close()
for itr in lines:
temp = itr.split()
if new_username in temp:
print("Username already exists!")
break
else:
break
else:
print("provide valid email address")
# This part verifies the password with the help of Password Class
for i in new_password:
new_password = input("Password: ")
c = Password()
if c.verify(new_password):
print("Registration Successful!")
break
File = open("Credentials.txt", "a")
File.write(new_username+" "+new_password+"\n")
File.close()
else:
print("Please make a valid choice")
# ....End of the Program....