All Tracks/lecture introduction to authentication and authorization/
Đang tải...
Hướng dẫn thử thách
1 / 5

How does Authentication and Authorization Work?

Imagine walking into a high-security office building. At the front desk, the security guard asks for your ID card to prove who you are. Once the guard verifies that your face matches the card, you walk through the lobby. However, when you try to swipe that same card to enter the executive server room, the scanner flashes red and denies you entry. This everyday scenario perfectly illustrates the two pillars of web security: **Authentication** and **Authorization**. While they sound similar and work together closely, they handle completely different jobs in a backend system. Authentication decides who you are. It's the process of verifying a user's identity. It answers one fundamental question, *"Is this person who they claim to be?"* When a user registers for an account, they provide a unique identifier, such as a username, email, a password, and other credentials. This information is then stored securely in the database. The next time the user visits and tries to log in, the backend system compares the credentials they type against the records stored in the database. Backend developers use three main categories of factors to authenticate users: - **Something you know:** A password, a PIN, or the answer to a security question. - **Something you have:** A physical smartphone receiving an SMS verification code, or a temporary token from an authenticator app. - **Something you are:** Biometric data like a fingerprint or a facial recognition scan. Once the system successfully authenticates the user, **Authorization** takes over and decides what the user is allowed to do or access. It answers a different question, *"What permissions does this specific identity have?"* Just because a user successfully logs in does not mean they should have total control over the application. Authorization defines the rules, roles, and boundaries for that user. Consider these common application roles: - **Standard User:** Can edit their own profile, but they cannot view other users' private billing information. - **Editor:** Can write and publish blog posts, but they cannot delete the entire website codebase. - **Admin:** Has full clearance to modify databases, delete users, and change system-wide settings. In backend code, authorization usually happens via middleware functions that check a user role or specific permissions before granting access to certain pages or data. To get these straight, remember this simple rule: **Authentication must always happen first, then authorization.** You cannot decide what permissions to give someone until you know exactly who they are. Authentication is the key that opens the front door, and authorization decides which rooms you can enter once you are inside.
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.sql
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵
Test Output
Thử thách này không có bài test tự động. Hãy quan sát kết quả trực tiếp ở khung Preview.