StoicBuilder

HandbookIII the CastraStoring passwords

IIIthe Castra, Stay in control

Storing passwords

1 min readUpdated 28 November

In plain words

Your app should never keep anyone's actual password, only a hash: a one-way scramble that can check a password but can't be turned back into it.

Where you see it

Open auth.users in Supabase and the encrypted_password column holds strings starting with $2a$, not real passwords. If one of your own tables has a column of readable passwords, the agent built its own login and got it wrong.

lib/auth.tsserver
import bcrypt from "bcryptjs"; // at sign-up: store only the hashconst hash = await bcrypt.hash(password, 12); // at login: compare, never decryptconst ok = await bcrypt.compare(attempt, user.password_hash);
There is nothing to decrypt. Login hashes the attempt and compares the two.

What goes wrong

  1. Saving the password as plain text

    One database leak exposes every password, including the ones people reuse for email and banking.

    insert into users (email, password) values ('maya@example.com', 'hunter2');
  2. Using a fast hash like MD5 or SHA-256

    Fast hashes can be guessed billions of times a second. Password hashes like bcrypt and Argon2 are slow on purpose.

  3. Emailing people their password

    Sending someone their password proves you're storing it readably. Send a reset link instead.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Let our auth provider handle email and password login instead of storing passwords in our own tables. If any table already holds passwords, show me which one, and switch to bcrypt or Argon2 hashes with a reset-link flow.

Quick check

Sign in to earn +10 XP for it

A user clicks "Forgot password" in Guildhall and receives an email containing their old password. What does that tell you?

Got a prompt that touches storing passwords?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.