Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple Passwords
#17
Best excuse for using a dictionary for this is if you are taking the next step and doing a username password combination. This is not the assignment so I don't think I violate rules by posting the code, but here:
import getpass
username = input("Input user name: ")
password = getpass.getpass("Password: ")
thisdict = {
  "sport": "football",
  "drink": "sprite",
  "food": "pizza",
    "woodrow": "roosevelt"
}
if username in thisdict:
    if thisdict.get(username) == password :
        print(f"Welcome {username}")
        #playgame()
    else:
        print(f"Oops {username}, can't find your username/password")
else:
    print(f"Oops {username}, can't find your username/password")
By using getpass, the password is entered as a row of stars. It then finds if username is in the dictionary, then checks to see if the password matches (you don't want to approve if the user name and password are in the dictionary but are not linked). You also want to give the same error message if the username is not found or if it is and the password doesn't match. Also note that the username and password are case sensitive.
Reply


Messages In This Thread
Multiple Passwords - by NotPythonQueen - Sep-21-2019, 06:38 PM
RE: Multiple Passwords - by buran - Sep-21-2019, 06:41 PM
RE: Multiple Passwords - by NotPythonQueen - Sep-21-2019, 06:47 PM
RE: Multiple Passwords - by buran - Sep-21-2019, 06:51 PM
RE: Multiple Passwords - by NotPythonQueen - Sep-21-2019, 06:57 PM
RE: Multiple Passwords - by buran - Sep-21-2019, 07:37 PM
RE: Multiple Passwords - by ichabod801 - Sep-21-2019, 09:27 PM
RE: Multiple Passwords - by NotPythonQueen - Sep-22-2019, 12:44 AM
RE: Multiple Passwords - by ichabod801 - Sep-22-2019, 01:19 AM
RE: Multiple Passwords - by NotPythonQueen - Sep-22-2019, 01:31 AM
RE: Multiple Passwords - by ichabod801 - Sep-22-2019, 01:57 AM
RE: Multiple Passwords - by NotPythonQueen - Sep-22-2019, 03:13 AM
RE: Multiple Passwords - by perfringo - Sep-22-2019, 04:15 AM
RE: Multiple Passwords - by NotPythonQueen - Sep-22-2019, 04:54 AM
RE: Multiple Passwords - by perfringo - Sep-22-2019, 06:05 AM
RE: Multiple Passwords - by buran - Sep-22-2019, 06:17 AM
RE: Multiple Passwords - by jefsummers - Sep-22-2019, 12:18 PM
RE: Multiple Passwords - by gbs - Sep-22-2019, 06:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Hashing Passwords (HELP) MianDoesCoding 4 2,256 May-26-2020, 03:11 PM
Last Post: buran
  Writing incorrect passwords to a file till its correct garth 2 5,010 Feb-10-2017, 11:41 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020