Why authentication matters
📖 Scenario: You are building a simple web app where users can see a secret message only if they are logged in. This helps protect private information from strangers.
🎯 Goal: Create a Flask app that stores a username and password, checks if the user is logged in, and shows a secret message only to logged-in users.
📋 What You'll Learn
Create a dictionary called
users with one user: username 'admin' and password 'secret123'Create a variable called
logged_in and set it to FalseWrite a function called
authenticate that takes username and password and returns True if they match the users dictionaryAdd a route
/login that sets logged_in to True if authentication succeedsAdd a route
/secret that shows 'Secret message: Flask is fun!' only if logged_in is True, otherwise shows 'Please log in first.'💡 Why This Matters
🌍 Real World
Authentication is essential to protect private data and control access in web apps.
💼 Career
Understanding basic authentication helps you build secure web applications and is a key skill for web developers.
Progress0 / 4 steps