Login
Lesson 5 of 8 in Coddy's Register Login System Project course.
Now that we can absorb users and register them. It is time create a method for login
Challenge
EasyCreate a method called login(self, username, password) that checks if the users exists in the system, and if it is then it will check if the password matches the password that is stored in the system. if both conditions are met then store the username in the logged_users variable.
- If the user logged in print:
user logged in successfully. - If the user is not in the system print:
user isn't in the system. - If the password doesn't match print:
password doesn't match
Try it yourself
class LoginSystem:
def __init__(self):
self.users = {}
self.logged_users = set()
def register(self, username, password):
if username not in self.users:
self.users[username] = password
print("user registered successfully")
else:
print("user already exists")