DEV3 Technologies home

DEV3 Developer Forum

Should I build authentication myself or use a library or service?

General IT0 views
dev3 ·

For my new app I need sign up, login, password reset and maybe social login. Is it okay to build auth myself, or should I use a package or a hosted service?

#authentication#security#architecture

0

1 reply

dev3 ·

Short answer: do not invent your own cryptography or session scheme. Use your framework's established authentication, or a well-maintained library or hosted service, and configure it carefully.

Why not roll your own

Authentication has many subtle failure modes: password storage, timing attacks, session fixation, token expiry, reset flows, rate limiting, account enumeration. Mature solutions have already seen these attacks.

Your options

  1. Framework built-ins or official packages. Most full-stack frameworks include authentication scaffolding. Low cost, full control, runs in your app.
  2. Auth libraries for your language, handling sessions, OAuth providers and tokens.
  3. Hosted identity services. They handle storage, social logins, multi-factor authentication and compliance features. You trade control and a recurring cost for less to maintain, and you take a dependency on the vendor.
  4. Self-hosted identity servers. Control and no per-user fee, but you operate them.

Choosing

  • Simple app, standard email and password: framework built-in is usually enough.
  • Need social login, enterprise single sign-on or many apps sharing logins: consider a hosted or self-hosted identity service.
  • Strict data residency: check where data is stored.

Whatever you pick, get these right

  • Hash passwords with a modern algorithm (bcrypt, scrypt or Argon2) with unique salts; never store plain text.
  • Use HTTPS everywhere and secure, HTTP-only cookies for sessions.
  • Rate limit login and reset endpoints.
  • Make reset tokens single-use, short-lived and stored hashed.
  • Return the same message for "unknown user" and "wrong password".
  • Offer two-factor authentication for important accounts.
  • Regenerate the session on login and invalidate it on logout.

Pitfalls

  • Storing tokens in places scripts can read.
  • Long-lived tokens with no revocation.
  • Rolling custom "remember me" logic.

Spend your effort on your product, and use the proven pieces for identity.

0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.