json and python login system
import json
print("LoginSystem @mvtthis")
myRL = input("Login or Register?")
if myRL == "Register":
User = input("Username:")
PW = input("Password:")
PW1 = input("Confirm Password:")
if(PW == PW1):
print("Registration successfully.")
with open('LoginSystemData.json', 'a') as f:
f.write("\n" + User + "," + PW)
else:
print("Registration failed! Please confirm your Password correctly.")
if myRL == "Login":
User = input("Username:")
PW = input("Password:")
success = False
with open('LoginSystemData.json', 'r') as f:
for i in f:
a,b = i.split(",")
b = b.strip()
a = a.strip()
if(a==User and b==PW):
print("Login successful")
else:
print("Login failed. Wrong Username or Password.")
f.close()
break
3.67
3
...
if myRL == "Login":
User = input("Username:")
PW = input("Password:")
with open('LoginSystemData.json', 'r') as f:
readable = f.read() # --> you need to readable:str your file
lines = readable.splitlines() # --> ['name,pw','name,pw','name,pw']
user = list(filter(lambda l:l.split(',')[0] == User and l.split(',')[1] == PW,lines))
if user:
print("Login successful")
else:
print("Login failed. Wrong Username or Password.")
f.close()
Thank you!
3
0
Are there any code examples left?
New code examples in category Python
-
Python 2023-04-11 03:04:20
-
Python 2022-03-27 22:40:04 pycharm no module named
-
Python 2022-03-27 22:25:05 assign multiple variablesin one line
-
Python 2022-03-27 22:20:02 levenshtein distance
-
Python 2022-03-27 21:35:09 get text from url python last slash
-
Python 2022-03-27 21:30:30 df concatenate df
-
Python 2022-03-27 21:25:09 python odd or even
-
Python 2022-03-27 21:15:32 python include function from another file
-
Python 2022-03-27 21:10:01 color module python
-
Python 2022-03-27 21:00:27 python tkinter cursor types