I rewrote as a class, there were just too many things wronf with the other code
Here's a complete class to get you started.
without that, this code is of little use.
If using a gui, you can use getpass (builtin)
Here's a complete class to get you started.
import json import os class NewPassword: def __init__(self, filename=None): self.usrdatalist = None self.filename = filename if self.filename is not None: if not os.path.exists(filename): self.init_file() else: with open(self.filename, 'r') as f: j = f.read() self.usrdatalist = json.loads(j) def init_file(self): data = [('user', 'password')] with open(self.filename, "w") as f: j = json.dumps(data) f.write(j) def rewrite_file(self): with open(self.filename, "w") as f: j = json.dumps(self.usrdatalist) f.write(j) def new_user(self): while True: username = input("Enter a username: ") if username in self.usrdatalist: username = input("Name taken, enter new name: ") continue break password = None while not password: password = input('Enter password: ') if len(password) < 12: print('Password must be at least 12 characters long') password = None continue self.usrdatalist.append((username, password)) self.rewrite_file() def main(): cp = NewPassword(filename="usrdata.json") cp.new_user() if __name__ == '__main__': main()The password needs to be encoded, double checked, and blanked out while entering
without that, this code is of little use.
If using a gui, you can use getpass (builtin)