Kunci Kas — Auth

Set up Kas Warga sign-in: sessions, hashing, TOTP, passkeys, lockout, RBAC and an audit trail. 14 levels, played right in the browser with nothing to install.

What you learn in this game

Authentication answers one question: who is using this app right now. The answer lives in a session, a random id in a browser cookie that points to a row on the server. In this game real Hono and real sessions run in the browser. The chips you pick complete server.js, then the villagers sign in from their phones for real. What is graded is who the server recognises, what it stores, and the trail it leaves, not the text of the code.

Hashing turns a password into a fingerprint that cannot be reversed. A salt is a unique scramble per password, so two people with the same password do not share a fingerprint. PBKDF2 here runs in the browser’s WebCrypto: it stores the fingerprint, and matches by recomputing it.

TOTP (RFC 6238) makes a code from a shared secret and the time, in thirty-second steps. The server and the app compute the same code as long as their clocks are close enough. Here the real otpauth library computes the code, on a phone clock made to drift on purpose.

A magic link is a random token emailed to you: click it and sign in without a password. Two rules are required: single use, and short-lived. Opening a link with a GET should not use it up, because mail scanners and message previews send GETs too.

A passkey (WebAuthn) uses a pair of cryptographic keys: the private key stays on the device and never leaves, the public key is kept by the server. There is no password to steal. rpID is the passkey’s owning domain. The browser refuses to make or use a passkey on a domain that is not its rpID. In this game it is the browser’s own WebAuthn that decides, with a virtual authenticator.

Lockout protects an account from repeated guessing. But a badly designed lockout becomes a weapon: if guessing someone’s name can lock their account, anyone can lock anyone. Two things matter: count per name and address, not name alone; and hold with a delay that grows then recovers, not a lock that cannot be opened.