Login Authentication

Simulate a simple login system by comparing username and password with stored values.

PythonBeginner
Python
# Simple login authentication

USERNAME = "admin"
PASSWORD = "secret123"

username = input("Enter username: ")
password = input("Enter password: ")

if username == USERNAME and password == PASSWORD:
    print("Login successful")
else:
    print("Invalid username or password")

Output

Enter username: admin
Enter password: secret123
Login successful

We store expected credentials in constants and compare user input against them. Both username and password must match for login to succeed.