Skip to content

About

Session-based authentication is a method where the server creates and stores a session for each authenticated user after they successfully log in. Banking portals, HR dashboards, ERP systems.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

🔑 What is Session-Based Authentication?

Session-based authentication is a method where the server creates and stores a session for each authenticated user after they successfully log in.

Here’s how it works step by step:

  1. User logs in with credentials (e.g., email & password).

  2. Server verifies the credentials against the database.

  3. If valid:

    • The server creates a session (usually an object with user info).
    • The session is stored on the server (in memory, a database, or a session store like Redis).
    • The server sends back a session ID to the client, typically stored in a cookie.
  4. On each request:

    • The client sends the cookie containing the session ID.
    • The server looks up the session using that ID.
    • If valid, the request is authenticated, and the server knows which user it belongs to.
  5. When the user logs out or the session expires, the session is destroyed, and the session ID becomes invalid.


⚖️ Session-Based vs Token-Based (JWT)

Feature Session-Based Authentication Token-Based Authentication (JWT)
Storage Server stores session data Client stores token, server is stateless
Scaling Harder (server must share sessions across instances) Easier (token validation doesn’t need server storage)
Security Session ID is secret, revocable at server JWTs can’t easily be revoked until expiry
Best for Web apps with cookies, server-managed auth APIs, mobile apps, microservices

✅ Use Cases for Session-Based Authentication

  1. Traditional Web Applications

    • Apps with server-rendered pages (e.g., Express.js with EJS, Django, Rails).
    • Example: Banking portals, HR dashboards, ERP systems.
  2. When Strong Control is Needed

    • Since sessions are stored on the server, you can immediately invalidate sessions (force logout).
    • Useful for apps requiring strong security, like admin dashboards.
  3. Small to Medium Apps

    • Easier to implement when scaling is not a huge concern (single server or sticky sessions).
  4. Apps where cookies are already used

    • Browsers handle cookies automatically, making session-based authentication a natural fit.

🔒 In short:

  • Session-based auth = server remembers you.
  • JWT-based auth = you carry your identity with you.

About

Session-based authentication is a method where the server creates and stores a session for each authenticated user after they successfully log in. Banking portals, HR dashboards, ERP systems.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages