Core Module
12 min forge
Authentication
Master the logic of digital identity. Learn how to verify who a user is using passwords, tokens, and multi-factor systems.
π Authentication (AuthN)
Authentication is the process of verifying the identity of a user, device, or system. It answers the question: "Who are you?"
π‘ The Logic (ELI5)
Think of an Airport Security Checkpoint:
- You hand the agent your Passport.
- They look at the photo and look at your face.
- They verify that you are indeed the person named on the passport.
- Conclusion: You are who you say you are. You have been authenticated.
- (Note: This doesn't mean you can get on the plane yet; that's Authorization!)
π The Deep Dive
Common Methods
- Passwords: Something you know. (Must be hashed/salted in the DB!).
- Tokens (JWT): A digital badge given to you after you log in. You show this badge for every future request.
- Session Cookies: The server remembers you by storing a "Session ID" in its memory or database.
- Biometrics: Something you are (Fingerprint, FaceID).
Modern Standard: JWT (JSON Web Tokens)
In distributed systems, JWTs are preferred because they are Stateless. The server doesn't need to check a database to know if the token is valid; it just checks the digital signature on the token itself.
π― Interview Pulse
AuthN vs AuthZ
Interviewers love to see if you confuse these two.
- Authentication (AuthN): Who are you? (Passport).
- Authorization (AuthZ): What can you do? (Boarding Pass).
Security Best Practices
- Hashing: Never store passwords as plain text. Use algorithms like
bcryptorargon2. - Salting: Adding random data to a password before hashing it to prevent "Rainbow Table" attacks.
- 2FA/MFA: Adding a second layer of security (e.g., an SMS code or Authenticator app).
Top Question
"Where do you store a JWT on the client?"
Answer: HttpOnly and Secure cookies are the safest option. Storing them in localStorage makes them vulnerable to XSS (Cross-Site Scripting) attacks.
π‘οΈ