Skip to content
Get started
Bastionary › Knowledge base › Migration

Replacing homegrown auth: migrating off the login you built in 2019

By Bastionary · Migration

The login you wrote in 2019 still works, which is exactly why it is dangerous. It handles passwords, it sets a session cookie, people log in every day — and it has quietly accumulated a list of things it does not do: no MFA, no SSO for the enterprise deal in the pipeline, no audit trail the compliance reviewer asked for, and a password-reset flow one developer understands. Homegrown auth is a liability the moment the business needs more from identity than the original author anticipated, and that moment usually arrives without warning.

The honest audit

You cannot migrate a system you only half understand, and homegrown auth is almost always under-documented. Before anything else, write down the truth about four things:

  • The hash. What algorithm, what cost factor, what salt scheme? bcrypt or argon2 is the lucky case. sha256(password + salt) is survivable. Unsalted md5 or sha1 is a security incident you have not declared yet.
  • The session. Server-side sessions in a store, or self-contained signed tokens? Where is the signing key, and how long do sessions live?
  • The user record. What is the canonical identifier — email, username, an internal id? Are emails unique and verified?
  • The edges. Password reset, email verification, "remember me," and any admin impersonation path. These are where homegrown systems hide their worst code.

Password hashes: three starting hands

Unlike migrating off a hosted provider, you own your hashes, which means in the good cases you can bring them straight across. The strategy depends entirely on what the audit found.

The lucky case: modern hashes

If passwords are already stored as bcrypt or argon2, you import the hash strings verbatim and your new platform verifies against them directly. No reset, no bridge, no user-visible change at all.

The common case: legacy but salted

If you stored, say, salted SHA-256, do a verify-then-upgrade on login: check the password against the legacy scheme once, and on success rehash it with a modern algorithm and overwrite the stored value.

def verify_and_upgrade(user, password):
    if user.hash_scheme == "argon2":
        return verify_argon2(user.password_hash, password)

    # Legacy: salted sha256 from the old system
    legacy = sha256((user.salt + password).encode()).hexdigest()
    if not constant_time_eq(legacy, user.password_hash):
        return False

    # Correct password under the old scheme -> upgrade in place
    user.password_hash = hash_argon2(password)
    user.hash_scheme = "argon2"
    user.salt = None
    db.save(user)
    return True

The bad case: broken hashes

If you find unsalted MD5/SHA-1, or passwords stored reversibly, treat the store as compromised. You can still migrate without a mass reset by wrapping: compute argon2(old_md5_hash) for every row in a batch job, store the wrapped value, and at login apply the same wrapping to the submitted password's MD5 before comparing. This upgrades the at-rest strength immediately without knowing any plaintext — then retire the weak inner hash via verify-then-upgrade as users log in, and force-reset the dormant tail.

Bridging sessions so nobody gets logged out

A flag-day cutover that invalidates every live session generates a support spike and trains users to distrust the change. Bridge instead. If the old system used server-side sessions, keep the old session store readable by the new platform during the transition and honor existing session IDs until they expire naturally, issuing new-format sessions on the next login. If it used signed tokens, have the new platform accept the old signing key for verification (never for new issuance) for a bounded window equal to your max session lifetime, then drop it.

Cut over by route, not by calendar

The safest migration is incremental and reversible. Rather than switching the whole app at once, move authentication surface area a piece at a time:

  1. Stand the new platform up alongside the old code, reading the same user table (or a replicated copy).
  2. Point new signups at the new platform first — the smallest blast radius, and it proves the write path.
  3. Route the login endpoint through the verify-then-upgrade bridge so existing users migrate as they authenticate.
  4. Move reset, verification, and MFA enrollment onto the new flows.
  5. When the active population has crossed and the old login endpoint sees only stragglers, retire it.

Keep the old user id as a stable external reference on every migrated record. Downstream systems, analytics, and support tooling almost certainly key off it, and quietly preserving it turns a hundred small breakages into zero.

What you gain the day you finish

The homegrown system was a fixed set of features frozen at the moment its author moved on. Replacing it with a real platform means MFA, passkeys, SSO, and an audit log stop being multi-quarter projects and become configuration. That is the actual payoff — not that the new login is prettier, but that the next identity requirement from sales or compliance is a setting rather than a sprint.

There is a second, quieter payoff: the bus-factor problem goes away. Homegrown auth is almost always load-bearing code that exactly one person fully understands, and that person's departure turns a routine change into a risk. A platform turns the login flow into documented, supported infrastructure that any engineer on the team can reason about, and it gives your security reviewers something they can actually audit instead of a bespoke module they have to take on faith.

Hand-rolled auth is the one piece of infrastructure almost every team outgrows and almost none enjoys maintaining. Moving off it does not have to mean handing your users' identities to a metered SaaS; you can migrate onto a platform you run yourself and keep the data exactly where it is now. Bastionary self-hosts next to your existing user table and supports verify-then-upgrade hashing, so the login you built in 2019 can retire without a flag day.

Run it yourself

Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.

Get started