Leaving Firebase Auth in a day
On 2 October 2026 customer sign-in moved from Firebase Auth to our own backend. Nobody had to reset a password: we check Firebase's hashes with Firebase's own algorithm, then rewrite each one in ours the first time its owner signs in.
Lodge Internet · 14 November 2026 · 5 min read
The day after the database moved to Postgres, sign-in was the last part of Lodge Internet still running on Firebase. Every customer's password lived there as a hash in Firebase Auth's own format, inside a system we were about to leave.
A forced password reset for everyone would have worked. It would also have sent every customer to their inbox on the day they wanted to buy Wi-Fi. We didn't want that, and in the end nobody had to reset anything.
The problem
You can't read a hashed password, which is the point of hashing it. So the passwords couldn't come with us. Only the hashes could, and a hash is useless unless you can run the same algorithm that made it.
Firebase uses its own variant of scrypt. It is documented, and Firebase publishes a reference implementation and a worked example. That made the plan possible: copy the hashes out, check them with Firebase's algorithm, and replace each one with our own the moment we see the real password again.
Firebase's hash, in our code
Firebase runs the password through scrypt with the user's salt plus a project-wide salt separator. It then uses the result as a key to encrypt a project-wide signer key with AES-256 in CTR mode. The output is the stored hash.
In backend/app/services/passwords.py that is a few lines:
def firebase_hash(password: str, salt: bytes, config: FirebaseHashConfig) -> bytes:
derived = hashlib.scrypt(
password.encode("utf-8"),
salt=salt + config.salt_separator,
n=2**config.mem_cost,
r=config.rounds,
p=1,
dklen=32,
maxmem=_MAXMEM,
)
encryptor = Cipher(algorithms.AES(derived), modes.CTR(b"\0" * 16)).encryptor()
return encryptor.update(config.signer_key) + encryptor.finalize()The project's parameters (the signer key, the separator, the rounds and the memory cost) were copied once from the Firebase console into our settings. The first test in tests/test_customer_sign_in.py reproduces Firebase's own published example, so we know the function matches theirs before it ever sees a real customer.
Two kinds of stored password
Every stored hash starts with a prefix that says which kind it is. firebase-scrypt$ is a hash copied out of Firebase. scrypt$ is ours: standard scrypt from Python's library, with no length limit and no extra dependency.
verify_password checks against whichever kind is stored. Then sign-in does one more thing:
if passwords.needs_rehash(creds.password_hash):
accounts.rehash(creds.user_id, creds.password_hash, passwords.hash_password(password))A successful sign-in with a Firebase hash rewrites it in our format, so we need Firebase's parameters less with every sign-in. The rewrite only lands if the stored hash is still the one that was just checked, so a password change made at the same moment wins. The same line would also upgrade our own hashes if we ever raised their cost.
One detail from the same function. When an email has no account, we still check the password against a decoy hash before refusing. A missing account takes as long to refuse as a wrong password, and both get the same message. A test pins that down.
Getting the hashes out
tools/auth_import.py loads Firebase's user export into a new user_credentials table. Two of Firebase's habits are handled in code.
First, Firebase will hand an export to an account that isn't allowed to read password hashes. It doesn't refuse. It fills the hashes with a placeholder instead. The tool checks for that and stops, asking for an export made with hash access, rather than importing a set of passwords nobody could ever match.
Second, Firebase had allowed two accounts to share one email. Our table has a unique email, so one had to win. The tool keeps the account that has a customer profile, then the one that signed in most recently. The other is a sign-up that was never used.
It is also safe to run again, so a second run just before the website moved over could catch accounts created since the first. A run adds new accounts and never overwrites a password the customer has already re-saved with us. It prints counts, never an email or a hash.
Sessions
Migration 0004 added two tables: user_credentials (one row per account: email, password hash, blocked or not) and user_sessions (one row per signed-in browser or bot chat). A session token is a session id and a secret joined by a dot. The table stores only a SHA-256 of the secret, so a copy of the database can't sign anyone in. The read-only reporting role can't read either table.
The website keeps its session token in a cookie no script can read. That design has its own post: No token in JavaScript. The bot is a server, not a browser, so it holds its token itself and swaps it for short-lived signed tokens on each call.
Three deploys, in order
The website and the backend deploy separately, so neither can assume the other has already changed. The switch went out as three deploys, each only after the one before was live:
- The backend learned the new sessions and cookies, while still accepting the old way of signing in.
- The website moved to the new sign-in.
- The backend stopped sending tokens to the website at all, and dropped the old way.
Then the old Firebase keys came off the server. The only Firebase settings we keep are the hash parameters above, which belong to the algorithm now, not to Firebase's service.
What customers saw
Anyone already signed in through Firebase was signed out and signed in once more, with the same password. A bot chat still holding a Firebase refresh token is refused like an expired one, and the bot asks the customer to log in again. No one reset a password.
Some accounts never had a password: ones the bot or a TV checkout created. Those sign in with an emailed code, or set a password through "forgot password".
The trade-off
Firebase-format hashes stay in our table until each of those customers comes back. Until then we keep Firebase's hash parameters, and they deserve the same care as any secret: with them and the hashes, an attacker can attempt to crack the old passwords just as they could have at Firebase.
Our own scrypt costs about 32 MB of memory and a few tens of milliseconds per check, on purpose. Routes call it through run_in_threadpool so a burst of sign-ins doesn't stall everything else the worker is doing.
What's still open
There is no cut-off in the code for the Firebase-format hashes. A customer who never signs in again keeps one forever, and we keep the parameters to check it.
If you are leaving a hosted auth provider, check first whether it publishes its hash algorithm. If it does, you probably don't need a forced reset.
Last checked against the product on 14 November 2026.