Sign out
Lesson 6 of 8 in Coddy's Register Login System Project course.
After users registered and logged in, they might want to sign out
Challenge
EasyCreate a method named sign_out(self, username). The method will check if the user exists in the system and then it will check if the user is logged in. If both conditions are met then the method will sign out the user.
- If the user does not exists in the system print:
user is not in the system. - If the is not logged in print:
user is not logged in. - If the user signed out successfully print:
user signed out successfully
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 successfuly")
else:
print("user already exists")
def login(self, username, password):
if username in self.users:
if password == self.users[username]:
self.logged_users.add(username)
print("user logged in successfully")
else:
print("password doesn't match")
else:
print("user isn't in the system")