Bitpath

Lesson 1 · Unit 03

Authentication

Sessions, tokens and second factors: proving who you are

13 exercisesabout 3 min

What you practise

  • Passwords, sessions and cookies vs tokens, what a JWT contains and what it must not, expiry and refresh, MFA, OAuth as "sign in with" in outline

Try a question from this lesson

Pick one

HTTP is stateless: every request arrives with no memory of the last. You log in once, then open ten pages. How does the server know requests 2 to 10 are yours?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Sessions

A session is a row on the server: a long random id, the user it belongs to, an expiry.

The cookie holds only the id. Everything else stays on the server, so logging out, or kicking out a thief, is just deleting the row.

Whoever holds the id is that user until it expires. Treat it like a temporary password.

cookie:  sid=9f2c...
server:  9f2c... -> user 42, until 18:00

Concept

Tokens: the JWT

A JWT is a signed token in three parts joined by dots: header.payload.signature.

The payload is base64-encoded JSON holding claims such as sub (who) and exp (when it expires). The server signs it with a key and later only checks the signature: no session table is needed.

Encoded is not encrypted. Anyone holding the token can read it.

eyJhbGciOiJIUzI1NiJ9     header
.eyJzdWIiOiI0MiJ9        payload
.4f9a...                 signature

10 more exercises in the app

  • 5× multiple choice
  • 1× fill the blanks
  • 1× true or false
  • 1× type the answer
  • 1× match the pairs
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy