+ 1
How can I use a dictionary to save passwords?
I want to search the keys and see if the user input matches the data i side the key. Nobody seems to use the dicrionary in that way. Is it even possible?
1 Resposta
+ 5
passwords should not be stored anywhere in your code, they should be stored in a separate encrypted file that your code can read from. If your purpose is just playing around with dictionaries then you could store the users name as the key and their password as the value and reference those when logging in. IE:
accounts = {} #empty dictionary
#add test account
name = "jake"#str(input())
passw = "12abC"#str(input())
accounts[name] = passw
#login (enter account info above for test)
name = str(input())
passw = str(input())
#check info exists and correct
if name in accounts.keys():
if passw == accounts[name]:
print("welcome,", name)
else:
print("wrong password")
else:
print("user does not exist")