Aug-02-2019, 08:54 PM
You can use dict to store usernames and passwords instead of list, and save dict to a file and load it each time when you run the *program check my example bellow
import json import os auth_file = "auth.json" auth = None def loadAuth(): if os.path.isfile(auth_file): return eval(open(auth_file).read()) return {} def saveAuth(): json.dump(auth, open(auth_file, 'wt')) if __name__ == '__main__': auth = loadAuth() operation = input('Login in or new user: ') if operation == 'login': username = input('username: ') password = input('password: ') if username in auth.keys() and auth[username] == password: print('Access granted') else: print('Access Denied - Wrong username or password') elif operation == 'new user': username = input('New username: ') password = input('New password: ') password_conf = input('confirm password: ') if password == password_conf: if username not in auth.keys(): auth[username] = password saveAuth() auth == loadAuth() print('Welcome ' + username) print (username,auth[username]) else: print ("Username already exists")