-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.py
358 lines (332 loc) · 10 KB
/
login.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#Admin usernames ('adminab','qwerty') or ('computer','010101')
import csv
import os
import random
import time
from getpass import getpass
import warnings
warnings.simplefilter("error", category=Warning)
def private():
s=''
letters='qwertyuioplkjhgfdsazxcvbnm'
letters+=letters.upper()
letters+='234567890'
letters+="!@#$%&*?/"
for i in range(8):
s+=random.choice(letters)
return 'AB '+s
passcode,correct = 0,private()
user = ''
def login(): #For Calling
global passcode,correct
if __name__ == '__main__': #Checking whether program called directly or by any other module
a=admin()
if a==True:
passcode=correct
return main()
else:
passcode=correct
return main()
os.system('cls')
count=0
def main(): #Main method of login.py
global passcode,correct
if passcode!=correct:
print("Fake")
os._exit(1)
return False
global count
print("\nIf you want to login as student, enter 1")
print("If you want to signup as student, enter 2")
print("If you want to login as admin, enter 3")
print("To exit, enter 0")
ch=input("-> ")
if ch=='':
choice=-1
else :
choice=int(ch)
if choice==1:
choice=0
if signin()==True:
return True
else:
return False
elif choice==2:
choice=0
signup()
return main()
elif choice==3:
choice=0
if admin()==True:
return True
else:
return False
elif choice==0:
choice=0
print("\nThanks for using this software.\n\tBy Bhav and Amanvir")
time.sleep(1.7)
print("\t\t ^ ^ ")
print("\t\t ! ` ` !")
print("\t\t ' ")
print("\t\t <-> ")
print()
print("You can run/download the project from the link \nhttps://github.com/bhavberi/LearningPython\n \tOr\nhttps://repl.it/@bhavberi/LearningPython")
time.sleep(2.8)
os._exit(1)
else:
count+=1
if count>3:
print("\nWrong inputs more than 3 times")
print("Program Terminating")
time.sleep(2.5)
os._exit(1)
else:
print("Please select correct option")
main()
def signup() :
d=dict()
ob=open('Login Details.csv','a+',newline='')
print('\n',end='')
while True:
print("Enter the username which you want to take(Atleast 3 letters long)\n(Condition to availability)")
username=input("-> ")
if len(username)<3:
print("\n")
continue
if username_checker(username):
break
else:
print("\nUsername not available\nPlease select any other username")
while True:
name=input("\nEnter your full name -> ")
if len(name)<1:
print("\n")
continue
else:
break
while True:
email=input("Enter your full email (in form of [email protected]) -> ")
if len(email)<5:
print("\n")
continue
if email_checker(email):
break
else:
print("Please try again")
while True:
phone=input("Enter your phone number(in form of ABCDEFGHIJ) -> ")
if phone_checker(phone):
break
while True:
city=input("\nEnter your city name -> ")
if len(city)<1:
print("\n")
continue
else:
break
while True:
try:
password=getpass("Enter password(min. 6 digits long) (Secured entry) -> ")
except:
password=input("Enter password(min. 6 digits long) -> ")
if len(password)<6:
print("\nPassword must be atleast 6 letters long")
continue
print('\nEntered Password -> ',end='')
print('*'*len(password))
try:
cpass=getpass("Confirm you password (Secured entry) -> ")
except:
cpass=input("Confirm you password -> ")
if cpass==password:
break
print("\nOriginal and Confirmatory Password's doesn't match\nPlease enter again.")
level='level 1'
while True:
print("\nEnter 1 for quizzes only package\nEnter 2 for complete package")
p=(input("-> "))
if len(p)==1 and p.isdigit():
p=int(p)
break
if p == 1:
package="Quiz"
elif p==2:
package='Complete'
else:
package='Complete'
print("Wrong Input\nYour package has been set to Complete")
cap_count=0
while True:
cap=captcha(random.randint(5,8))
cap_count+=1
print("Please enter this captcha (Case Sensitive) \nfor verification that user is not robot")
print(cap)
cap1=input('-> ')
if cap1==cap:
break
print("\nWrong Captcha Entered")
if cap_count==3:
print("\nCaptcha validation failed")
print("Program Terminating")
time.sleep(2.5)
os._exit(1)
print("You have only",3-cap_count,'chances left')
d['username']=username
d['password']=password+'#ab'
d['level']=level
d['package']=package
d['name']=name
d['email']=email
d['phone']=phone
d['city']=city
fields=['username','password','level','package','name','email','phone','city']
data=csv.DictWriter(ob,fieldnames=fields)
data.writerow(d)
ob.close()
def username_checker(username):
with open('Login Details.csv','r') as ob:
data=csv.reader(ob)
if username=='adminab' or username=='computer' or username=='admin':
return False
for i in data:
if i[0]==username:
return False
return True
def email_checker(email):
email.strip()
with open('Login Details.csv','r') as ob:
data=csv.reader(ob)
for i in data:
if i[5]==email:
print("\nEmail already exists")
return False
for i in range(len(email)):
if email[i]=='@':
a=email[i+1:]
for j in range(len(a)):
if a[j]=='.':
b=a[j+1:]
if b!='':
return True
else:
break
print("\nPlease check your email")
return False
def phone_checker(phone):
if len(phone)<10 or len(phone)>10:
print("\nEnter complete phone number of 10 digits\nPlease try again")
return False
if not phone.isdigit():
print("\nPlease enter correct phone number")
return False
with open('Login Details.csv','r') as ob:
data=csv.reader(ob)
for i in data:
if i[6]==phone:
print("\nPhone Number already exists\nPlease try Again")
return False
return True
def captcha(l):
s=''
letters='qwertyuiplkjhgfdsazxcvbnm'
letters+=letters.upper()
letters+='123456789'
letters+="!@$%^&*?/'"
for i in range(l):
s+=random.choice(letters)
return 'AB '+s
def admin(): #For login of Admin
global count,user
count+=1
if count>4:
print("Entered wrong information more than 3 times !!!")
time.sleep(2.5)
os._exit(1)
username=input("Enter username to login with (as admin) -> ")
username.lower()
if username!='adminab' and username!='computer':
print("Wrong Username")
admin()
try:
password = getpass("Enter password for username "+username+" (Secured entry) -> ")
except:
password = input("Enter password for username "+username+" -> ")
print('\n',end='')
cap_count=0
while True:
cap=captcha(random.randint(6,8))
cap_count+=1
print("\nPlease enter this captcha (Case Sensitive) \nFor verification that user is not robot")
print(cap)
cap1=input('-> ')
if cap1==cap:
break
print("\nWrong Captcha Entered")
if cap_count==3:
print("\nCaptcha validation failed")
print("Program Terminating")
time.sleep(2.5)
os._exit(1)
print("You have only",3-cap_count,'chances left')
if username=='adminab' and password=='qwerty':
print("Admin Logged In")
time.sleep(2.5)
user=username
return True
#os._exit(1)
elif username=='computer' and password=='010101':
print("Admin Logged In")
time.sleep(2.5)
user=username
return True
else:
print("\nWrong Password ")
admin()
def signin(): #For login of student
global count
count+=1
if count>4:
print("Entered wrong information more than 3 times !!!")
print("Program Terminating")
time.sleep(2.5)
os._exit(1)
username=(input("Enter the username of the student -> ")).lower()
try:
password = getpass("Enter password (Secured entry) -> ")
except:
password = input("Enter password -> ")
password+='#ab'
print('\n',end='')
cap_count=0
while True:
cap=captcha(random.randint(6,8))
cap_count+=1
print("\nPlease enter this captcha (Case Sensitive) \nFor verification that user is not robot")
print(cap)
cap1=input('-> ')
if cap1==cap:
break
print("\nWrong Captcha Entered")
if cap_count==3:
print("\nCaptcha validation failed")
print("Program Terminating")
time.sleep(2.5)
os._exit(1)
print("You have only",3-cap_count,'chances left')
with open('Login Details.csv','r') as ob:
data=csv.reader(ob)
for i in data:
if i[0].lower()==username:
if i[1]==password:
print("\nLOGGED IN ")
time.sleep(3.5)
global user
user=username
return True
print("\nWrong Username or Password Information")
signin()
def username():
global user
return user
if __name__ == '__main__':
login()