Soz probs stupid question, but I cannot seem to get my login to accept any usernames or passwords when I reach the login function after adding usernames and passwords from the register function, instead if I enter nothing at all as inputs, it will still proceed and be counted as logged in. I also have a minor error where if I select option A, it asks for the input twice before accepting it. Any help would be appreciated thanks.
store = [] <---The list that stores the usernames and passwords
def menu():
mode = input("""Choose options:\n
##########################################################################
a) Login with username and password
b) Add username and passwords to list
To select a mode, enter the corresponding letter of the mode below
##########################################################################\n
> """.format(name)).strip()
return mode
def login():
if len(store) > 0 : #user has to append usernames and passwords before it asks for login details
print("Welcome to the login console")
while True:
username = input ("Enter Username: ")
password = input ("Enter Password: ")
for i in store: #finds usernames and passwords in the store list
if i == username and i == password: break
print("Username matches!")
print("Password matches!")
logged() #jumps to logged function
else:
print("You have no usernames and passwords stored!")
def register(): #example where the username is appended. Same applies for the password
print("Please create a username and password to be stored in a list.\n")
while True:
validname = True
while validname:
username = input("Please enter a username you would like to add to the password vault. NOTE: Your username must be at least 3 characters long: ").strip().lower()
if not username.isalnum():
print("Your username cannot be null, contain spaces or contain symbols \n")
elif len(username) < 3:
print("Your username must be at least 3 characters long \n")
elif len(username) > 30:
print("Your username cannot be over 30 characters \n")
else:
validname = False
store.append([username]) <-----(USERNAME IS APPENDED TO THE STORE LIST)
validpass = True
while validpass:
password = input("Please enter a password you would like to add to the password vault. NOTE: Your password must be at least 8 characters long: ").strip().lower()
if not password.isalnum():
print("Your password cannot be null, contain spaces or contain symbols \n")
elif len(password) < 8:
print("Your password must be at least 8 characters long \n")
elif len(password) > 20:
print("Your password cannot be over 20 characters long \n")
else:
validpass = False #The validpass has to be True to stay in the function, otherwise if it is false, it will execute another action, in this case the password is appended.
vault.append([password])
validinput = True
while validinput:
exit = input("\nEnter 'end' to exit or any key to continue to add more username and passwords:\n> ")
if exit in ["end", "End", "END"]:
menu()
else:
validinput = False
register()
return register
def logged():
print("-----------------------------------------------------------\n")
print("Hello, you are logged in. ")
while True:
chosen_option = menu() #a custom variable is created that puts the menu function into the while loop
if chosen_option in ["a", "A"]:
login()
if chosen_option in ["b", "B"]:
register()
else:
print("""That was not a valid option, please try again:\n """)
Aucun commentaire:
Enregistrer un commentaire