I have to make a login program where the username and password are taken from an existing file.
I have successfully, in my opinion, opened, read, and brought out all the user names and passwords from the file.
The problem is, the user is only allowed to input an incorrect username 3 times before the program end.
Also, the user is given a total of 10 tries all together. (ex. user puts 2 wrong usernames before putting in the right one, then they have 8 tries to input a correct password or, again, the program ends.)
Here's what I have
def main():
file = open("names.txt", 'r')
line = file.readline()
A={}
s=line.split()
user=s[3]
password=s[4]
name=input("Username: ", )
code=input("Password: ", )
for i in range(3):
if name in user:
print("welcome", name)
else:
print("Incorrect username")
main()
I'm not sure how to put it so that it the input of the username is given 3 attempts and that the password is given 10(if username correct), 9(if one incorrect username), and 8(if two incorrect username) tries.