Bugpit

Lessons › Core concepts

Who are you, and what may you do?

Your app checks passwords itself, and the database password is written in the code. 5,000 req/s arrive, and every one of them must know who the user is.

Play this level

Free with an account. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

Authentication asks who you are, for example with a password, a passkey or Google sign-in. Authorization asks what you may do, for example whether you may see this invoice.

Never store passwords, even encrypted. Store a slow hash made with bcrypt or Argon2, so a stolen table is still hard to use. After sign-in, a signed token such as a JWT lets any server check the user without a database call. Keep tokens short-lived, because a signed token can't easily be taken back.

Encrypt data in transit with TLS and at rest on disk. Keys and passwords belong in a secrets manager, not in code, where every copy of the repository would hold them.

What you have to achieve

5,000 requests a second at the busiest hour, 10% of them writes.

What you learn

Sign-in now lives in one service with enough room for every request, and no password sits in your code. Who you are and what you may do are separate questions, answered on every request.

Check yourself

Which question does authorization answer?

Show the answer

What are you allowed to do?. Authentication checks who you are. Authorization checks whether that person may do this particular thing.

How should passwords be stored?

Show the answer

As a slow hash, such as bcrypt or Argon2. You never need to read a password back, only to check one. A slow hash makes a stolen table very costly to crack.

What's the main risk of a JWT that lasts a month?

Show the answer

If it's stolen, it can't easily be taken back. Servers trust a signed token without asking anyone, so a stolen one works until it expires. Short-lived tokens with refresh tokens limit the damage.

Where should the database password live?

Show the answer

In a secrets manager. Code is copied to every laptop and build server. A secrets manager controls who can read it and lets you change it without a release.

Try it yourself

More in Core concepts

← How services talk See inside your system →