63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
users = {
|
|
"john": "password",
|
|
"jane": "1234",
|
|
"alice": "31234",
|
|
"charlie": "1863",
|
|
"david": "3958",
|
|
}
|
|
|
|
def login():
|
|
for i in range(3):
|
|
username = input("Enter username: ").strip().lower()
|
|
password = input("Enter password: ").strip()
|
|
|
|
if username in users and users[username] == password:
|
|
return True
|
|
|
|
return False
|
|
|
|
def add_user():
|
|
username = input("Enter new username: ").strip().lower()
|
|
if username in users:
|
|
print(f"User '{username}' already exists.")
|
|
return
|
|
|
|
password = input("Enter password: ").strip()
|
|
users[username] = password
|
|
print(f"User '{username}' added successfully!")
|
|
|
|
def remove_user():
|
|
username = input("Enter username to remove: ").strip().lower()
|
|
if username not in users:
|
|
print(f"User '{username}' not found.")
|
|
return
|
|
|
|
del users[username]
|
|
print(f"User '{username}' removed successfully!")
|
|
|
|
def list_users():
|
|
print("Current users:", list(users.keys()))
|
|
|
|
def main():
|
|
while True:
|
|
print("\n1. Login\n2. Add user\n3. Remove user\n4. List users\n5. Exit")
|
|
choice = input("Enter choice: ").strip()
|
|
|
|
if choice == '1':
|
|
if login():
|
|
print("Login successful!")
|
|
else:
|
|
print("Invalid username or password.")
|
|
elif choice == '2':
|
|
add_user()
|
|
elif choice == '3':
|
|
remove_user()
|
|
elif choice == '4':
|
|
list_users()
|
|
elif choice == '5':
|
|
break
|
|
else:
|
|
print("Invalid choice.")
|
|
|
|
if __name__ == "__main__":
|
|
main() |