Bwf/ GuideFrançais
Bwf Guide

Password authentication

We’ll follow a Journal account from registration to its next sign-in. Along the way we’ll see what goes into the account table and how the controller starts a session.

Keep the lookup in the controller

Choose which account field your reader will use to sign in, and look up that row in the controller. Bwf provides password hashing, verification and session support. Your application decides how to recover an account or ask for another identity check.

Django authentication

Save the encoded verifier

On registration, pass the password to Auth.hash and store the encoded salted scrypt verifier it returns. Later, when the reader signs in, fetch that row with a parameterized query. Give Auth.verify the newly submitted password and the verifier from that row.

This binding goes in the registration action’s IO block.

hash <- Auth.hash(password)

Start a fresh session on login

Render the login form with a session so the browser receives its CSRF token. Once the password checks out, give the sign-in response the account ID and a GET destination. Bwf rotates the session and CSRF tokens as part of signing the reader in.

The Journal redirects to its home GET after a successful login.

Api.Login303{
  Contract.SignIn{context, id, Api.target_home(None{}, None{}, None{})}
}

Sign out and go home

A signed-in operation receives a Controller.SignedIn value. To sign out, invalidate the server-side session and expire its cookie. Sessions and cookie context lists the other access levels.

Here the logout action returns the constructor that clears the session and redirects.

Api.Logout303{
  Contract.SignOut{context, Api.target_home(None{}, None{}, None{})}
}

Exercise sign-in and sign-out over HTTP

On a running Journal, sign in with a wrong password, then with the correct password. After login, open Settings and check the account details. Sign out and revisit the settings URL to check that access has ended.

Try it in the Journal

Register two readers