Python Forum
Quick Question about Dictionaries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quick Question about Dictionaries
#1
Hello,

I'm trying to make a simple login page through the terminal and I decided to use a dictionary to store the user's name and password.

As show in my code here (Ya I realize now, I probably don't need the whole function housing the dict):
def StandardUsers():
    users = {
        "Bob" : 1234,
        "Jim" : 5678,
        "Roger" : 9101,
        "Frank" : 8877
    }
    return users

def SuperUsers():
    admins = {
        "Joe" : 0000,
        "Randall" : 1111
    }
    return admins
(Ex: "Bob":1234 Where "Bob" is the user's name and 1234 is the password)

And I have an input statement that takes in the user's name and password as shown here:

def login():
    print('=============================')
    print('= Login =')
    print('=============================')
    user = input("Enter your name: ")
    password = input("Enter your password: ")
    validate() #Go to validate function
And this is my validate function that I have right now:
def validate(user):
    #if StandardUsers enters in correct name and password:
        MainMenu()

    #if SuperUsers enters in the correct name and password:
        AdminMenu()
        
    else:
        print('You are not registered to use this program')
        login()



My question is: how do I validate the user's name and password in an if statement so they can get to the menu? (How do I check to make sure the key, value pairs in the dict match, and apply them to my validate function)

Thanks in advance.
Reply


Messages In This Thread
Quick Question about Dictionaries - by Extra - Apr-29-2022, 05:14 PM
RE: Quick Question about Dictionaries - by Extra - Apr-29-2022, 05:48 PM
RE: Quick Question about Dictionaries - by Extra - Apr-29-2022, 05:51 PM
RE: Quick Question about Dictionaries - by Extra - Apr-29-2022, 08:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Question about working with dictionaries Ashcora 13 2,147 Dec-27-2022, 09:09 PM
Last Post: Ashcora
  Quick question/help regarding my variable Extra 5 1,585 May-06-2022, 12:01 AM
Last Post: Extra
  quick question/excel+python zarize 1 2,283 Dec-06-2019, 05:38 PM
Last Post: Larz60+
  A quick question teczone 4 3,115 Sep-06-2018, 03:44 PM
Last Post: snippsat
  Completely new to coding - quick question Oster22 1 2,723 Jun-19-2018, 08:42 PM
Last Post: Larz60+
  Quick help! Ellisrb 2 2,783 May-02-2018, 11:21 AM
Last Post: ThiefOfTime
  Quick Lists Question (Count Occurences) EwH006 9 8,098 Nov-16-2016, 04:33 PM
Last Post: Larz60+
  quick question about deleting an object from memory LavaCreeperKing 5 5,870 Nov-12-2016, 04:05 PM
Last Post: LavaCreeperKing
  quick way to convert in both 2 and 3 Skaperen 10 8,820 Nov-03-2016, 04:43 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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