Back to Coding

How Do You Handle Sign In and Accounts?

How Do You Handle Sign In and Accounts?
AI Tutorials Team 21 February 2026

Login looks simple: a form, a password check, a session. It is one of the most consistently underestimated pieces of any application, and it is the one where a subtle mistake is a breach rather than a bug.

What is the recommendation?

Use something established rather than writing it. Your framework's authentication library, or a hosted identity provider, both handle a long list of details that a hand-written version misses.

This is not caution for beginners; experienced developers reach for the library too, because the list is long and unforgiving.

What does that list include?

  • Password hashing. With a current algorithm and appropriate cost.
  • Session handling. Secure cookies, expiry, invalidation on logout.
  • Rate limiting. Against repeated attempts.
  • Reset flows. Which are a common weak point.
  • Timing-safe comparison. Which is easy to get wrong invisibly.
  • Not revealing whether an account exists.

What do generated implementations get right?

The obvious parts. Hashing rather than storing plain passwords, and a broadly sensible session arrangement. It reflects widely published practice, which is generally sound for the common path.

What do they miss?

The edges. Session invalidation on password change, reset tokens that expire and can be used once, protection against enumeration, and anything about your specific authorisation rules.

Authorisation in particular is invisible to a reviewer that does not know your rules, and it is where most real breaches occur.

Two-factor authentication is worth considering once anything valuable is behind the login, and every established library supports it, which is another reason not to write your own.

What is the difference that matters?

Authentication is who somebody is; authorisation is what they may do. A library handles the first entirely and cannot handle the second, since only you know that a user may see their own records and not somebody else's.

Every route that returns data needs that check, and forgetting one is the most common serious flaw in small applications.

What is the check worth running?

List every route in this application, what data it returns or modifies, and what authorisation check it performs. Point out any route where a signed-in user could access something belonging to another user by changing an identifier in the request.

Should you use social sign in?

For a small project it removes password handling, reset flows and storage of credentials entirely, which is a substantial reduction in what can go wrong. The trade is a dependency on a third party and a data protection consideration about what is shared.

Deleting an account properly is worth building early rather than later, since somebody will ask and doing it by hand across six tables is exactly the situation to avoid.

What about the accounts you cannot avoid?

Keep them minimal. Email and password, no profile, no preferences, no display name until something needs one. Every field stored about a person is something to protect, and the smallest possible account is the easiest to justify.

What about staying signed in?

Convenient and worth thinking about rather than accepting the default. A session that lasts indefinitely is pleasant for the user and means a stolen device or an unattended browser has access for as long as nobody notices.

The reasonable arrangement for a small application is a session lasting days rather than months, with re-authentication required before anything consequential such as changing an email address or a password. Generated implementations rarely include that second part, and it is the thing that limits the damage when a session is used by somebody it should not be.

What is the position worth holding?

Never write the cryptography, always write the authorisation. Delegating the first is sensible and delegating the second is impossible, because nobody else knows your rules. That division covers most of what goes wrong here.