Python Forum
Login with using class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login with using class
#2
class userpass:
    users = {"meryem":"4444","ahmet":"sehir123","gakkos":"2323"}
    inventory = {'asparagus': [10, 5], 'broccoli': [15, 6], 'carrots': [18, 7],
             'apples': [20, 5], 'banana': [10, 8], 'berries': [30, 3],
             'eggs': [50, 2], 'mixed fruit juice': [0, 8], 'fish sticks': [25, 12],
             'ice cream': [32, 6], 'apple juice': [40, 7], 'orange juice': [30, 8],
             'grape juice': [10, 9]}
    market_inventory = []
    customers_basket = []
    def login(self):
        while True: #added
            login = raw_input('Username:')
            if login in self.users.keys():
                psw = raw_input('Password:')
                if self.users[login] == psw:
                    print 'Successfully logged in!','\n','Welcome,',login,"Please choose one of the following options by entering the corresponding menu number."
                    break #added
                else:
                    print 'Your user name and/or password is not correct. Please try again!'
            else:
                print "Your user name and/or password is not correct. Please try again!"
            
Output:
>>> log = userpass() >>> log.login() Username:gakkos Password:2323 Successfully logged in! Welcome, gakkos Please choose one of the following options by entering the corresponding menu number. >>>
recapping/learning while providing solution , wont mind if someone will correct me, i appreciate that.
i assume you hv done this in python 2.x (raw_input function available) so i left out the brackets in print statement.
i added while and break statement so the code will keep asking for correct username & password
swallow osama bin laden
Reply


Messages In This Thread
Login with using class - by captainflint - Feb-02-2018, 05:28 PM
RE: Login with using class - by ka06059 - Feb-03-2018, 06:12 AM
RE: Login with using class - by captainflint - Feb-03-2018, 01:01 PM
RE: Login with using class - by Gribouillis - Feb-03-2018, 06:58 AM
RE: Login with using class - by ka06059 - Feb-03-2018, 03:13 PM

Forum Jump:

User Panel Messages

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