json and python login system

Solutions on MaxInterview for json and python login system by the best coders in the world

showing results for - "json and python login system"
Aidan
14 Feb 2018
1import json
2
3
4print("LoginSystem @mvtthis")
5myRL = input("Login or Register?")
6
7
8if myRL == "Register":
9    User = input("Username:") 
10    PW = input("Password:")
11    PW1 = input("Confirm Password:")
12
13    if(PW == PW1):
14        print("Registration successfully.")
15        
16        with open('LoginSystemData.json', 'a') as f:      
17                f.write("\n" + User + "," + PW)
18                
19    else:
20        print("Registration failed! Please confirm your Password correctly.") 
21
22if myRL == "Login":
23    User = input("Username:") 
24    PW = input("Password:")
25    success = False
26    with open('LoginSystemData.json', 'r') as f: 
27        for i in f:
28            a,b = i.split(",")
29            b = b.strip()
30            a = a.strip()
31            if(a==User and b==PW):
32                print("Login successful")
33            else:
34                print("Login failed. Wrong Username or Password.")     
35            f.close() 
36            break
37
Royce
11 Sep 2017
1...
2
3if myRL == "Login":
4    User = input("Username:") 
5    PW = input("Password:")
6    with open('LoginSystemData.json', 'r') as f: 
7        readable = f.read() # --> you need to readable:str your file
8        lines = readable.splitlines() # --> ['name,pw','name,pw','name,pw']
9        user = list(filter(lambda l:l.split(',')[0] == User and l.split(',')[1] == PW,lines))
10        if user:
11               print("Login successful")
12        else:
13               print("Login failed. Wrong Username or Password.")     
14        f.close()
15