惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
博客园 - 叶小钗
The Cloudflare Blog
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
小众软件
小众软件
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
宝玉的分享
宝玉的分享

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Authentication vs Authorization (Like I'm 5 years Old)
Tawanda Nyah · 2026-04-26 · via DEV Community

You are probably wondering why this guy is writing an article on this. Is this some AI slop or what? They keep asking this question in interviews; it is our duty to put it out there and flood the internet with it until everyone easily understands it.

Besides, people have different ways of understanding different concepts. So after reading this article, go out there and write about it in your own words. The internet needs more of that.

The candy store door vs the candy aisle

Authentication is the candy store door. There's a guard at the entrance who checks your ID before letting you in. No ID, no entry. It does not matter how much you want the candy; you need to prove who you are first.

Authorization is the candy aisle. You're inside the store now, but that doesn't mean you can go everywhere. Customers stay in the aisles. The stockroom? Staff only. The manager's office? Don't even think about it. Where you're allowed to go depends on who you are, and that's authorization.

Authentication: Can you get through the door? → prove who you are

Authorization: Which aisles can you walk down? → decided once you're inside

Enter fullscreen mode Exit fullscreen mode

How it actually works in software — JWT

When you log into an app, the server needs a way to remember you without asking for your password on every single click. This is where JSON Web Tokens (JWT) come in.

Think of a JWT as the receipt the guard gives you after checking your ID at the candy store door. Every time you want to grab something off a shelf, you show the receipt, so the staff doesn't need to call the guard again. They check the receipt and know exactly who you are and what you're allowed to pick up.

A JWT has three parts separated by dots:

header.payload.signature

Header → algorithm used to sign it
Payload → user info, roles, expiry
Signature → proof it hasn't been tampered with

Enter fullscreen mode Exit fullscreen mode

The server signs the token when you log in. Every request you make after that carries the token in the header. The server verifies the signature, and if it checks out, it trusts the payload. No database lookup needed on every request. Fast, stateless, and widely used in REST APIs

Authorization in the real world — RBAC

Once a user is authenticated, the system needs to decide what they can do. The most common approach is Role-Based Access Control (RBAC).

Instead of assigning permissions to individual users which gets messy fast, you assign them to roles. Then users are given a role. Back to the candy store: customers can browse the aisles, staff can access the stockroom, and managers can open the safe. Same store, completely different access.

Role    Can read    Can delete
Admin   Yes         Yes
Editor  Yes         No
Viewer  Yes         No

Enter fullscreen mode Exit fullscreen mode

In a JWT, the user's role is often stored right in the payload. So when the server decodes the token, it sees role: admin and knows exactly what that person is allowed to do no extra database call required.

Putting it all together

Here's the full flow in a typical web app:

  1. User logs in with credentials → server verifies → authentication (through the door)
  2. Server issues a signed JWT with the user's role baked in (the receipt)
  3. User sends JWT on every request
  4. Server checks the role in the token → grants or denies access → authorization (which aisle)