I have started learning python about 2 weeks ago and am trying to create a password system that can store multiple usernames and passwords. I am trying to add a bit of code where it makes you wait a minute if you input a wrong password 3 times.
I keep on getting an error where if you get the password wrong 3 times and wait the 60 seconds, even if you do input the right password and username it prints "Your password is wrong. You have only 3 attempts left."
Can somebody help and point out flaws that I have in the code?
import time username = ["Test","Test2"] password = ["1Ac!","2Bd!"] success = 0 Tries = 0 Valid = False Pass = "" def login(): global success global Pass global Tries inuser = input(str("Enter your username: \n")) inpass = input(str("Enter your password: \n")) if inuser not in username: print("username not found in directory") login() else: posUser = username.index(inuser) Pass = password[posUser] while success != 1: if Tries == 3: print("You have had too many attempts. Wait 60 seconds before trying again") for i in range(60, 0, -1): time.sleep(1) print(i) if Tries == 3: Tries = 0 inuser=str("0") inuser=str("0") login() else: break if Pass == inpass: success=1 else: Tries += 1 AttemptsLeft = (3 - Tries)+ 1 print("Your password is wrong. You have only {} attempts left.".format(AttemptsLeft)) login() login() if success==1: print("Welcome to ------")
username[i]haspassword[i]. You can make that more explicitly, for example with something likeaccounts = [("Test", "1Ac!"), ("Test2", "2Bd!")]oraccounts = {"Test": "1Ac!", "Test2": "2Bd!"}.