TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Has anyone built their own authentication system?

19 pointsby goldname10 months ago
I'm building out a website (never did full stack before) and am implementing authentication. It's turning out to be more work than I expected. Is it unreasonable to implement auth yourself with JWTs? You also need to setup email sending for verification which takes more time.

11 comments

dvektor10 months ago
Yes, several. This is going to be a controversial one... but it isn&#x27;t nearly as difficult as people make it seem. You shouldn&#x27;t roll your own crypto libraries, but storing a bcrypt hash of the users password in the database, and then creating a JWT and setting it in a cookie, or create a session table and store a UUID in the cookie as a key to the session table really isn&#x27;t that difficult.<p>Personally I think the problem is we are being sold so many &#x27;conveniences&#x27;&#x2F;solutions these days. They want you to think you cannot safely do it yourself, and on top of that, often times it&#x27;s actually more difficult just to learn how to use whatever API the convenience that&#x27;s being sold to us, uses.<p>You are often better off learning what is really happening under the hood, and solving the actual problem, instead of trying to figure out whatever api&#x2F;tool that is being sold to you as a convenience. EDIT: to clarify, if you are inexperienced: I recommend learning by implementing both session + JWT auth on a side project, before using hand-rolled solutions in production.
评论 #41014230 未加载
评论 #41014268 未加载
评论 #41015261 未加载
评论 #41015240 未加载
curtisblaine10 months ago
I have, and the basic username &#x2F; bcrypted &#x2F; scrypted password &#x2F; JWT implementation was quite easy. What I found difficult* was all the accessory quality of life functionalities, e.g. password reset via mail, automated backups, 2 factor authentication, social login etc. You might not want all of them, but email verification &#x2F; reset is kinda the expected baseline and it means you have to use an external mail-sending system anyway.<p>*difficult not as in &quot;hard to implement&quot;, more as in &quot;lots of moving parts, hard to maintain&quot;
a02231110 months ago
It&#x27;s actually very easy to implement your own authentication. You should use either Argon2 or Bcrypt to store passwords. If the website is small, you shouldn&#x27;t use JWTs (see <a href="https:&#x2F;&#x2F;blog.ploetzli.ch&#x2F;2024&#x2F;should-i-use-jwt-for-authentication&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.ploetzli.ch&#x2F;2024&#x2F;should-i-use-jwt-for-authentic...</a>). Ideally, you should use an encrypted HttpOnly cookie with SameSite=strict, etc. which you can optionally sign just like you would sign a JWT although that&#x27;s unnecessary. You might also find this useful: <a href="https:&#x2F;&#x2F;cheatsheetseries.owasp.org&#x2F;cheatsheets&#x2F;Authentication_Cheat_Sheet.html" rel="nofollow">https:&#x2F;&#x2F;cheatsheetseries.owasp.org&#x2F;cheatsheets&#x2F;Authenticatio...</a>
评论 #41015483 未加载
gregopet10 months ago
For a simple website JWTs are almost definitely an overkill (you would get all the drawbacks for none of the benefits). A session based authentication with some libs from your ecosystem for the crypto parts and a nice intro on how to combine them together could be the perfect thing for you.
评论 #41014416 未加载
ab_testing10 months ago
If you are using python and flask for building the web application, then there is a well defined tutorial on implementing user login and password.<p><a href="https:&#x2F;&#x2F;blog.miguelgrinberg.com&#x2F;post&#x2F;the-flask-mega-tutorial-part-i-hello-world" rel="nofollow">https:&#x2F;&#x2F;blog.miguelgrinberg.com&#x2F;post&#x2F;the-flask-mega-tutorial...</a>
aristofun10 months ago
I had to implement my own because all the alternatives were some combination of 1. Crap 2. Over complicated for my needs 3. Ridiculously expensive<p>Unless you are more experienced and smarter than average engineer working on a 3d party solution - you should build your own only for educational purposes.
notpushkin10 months ago
As others have pointed out, rolling your own simple username-password auth isn&#x27;t too hard. As you go forward, you might need to add other things like 2FA or social login or SAML, and those things aren&#x27;t exactly hard either (there&#x27;s TOTP validation libraries in most languages I think, and for SAML you can use Jackson [1] which translates it to OIDC for you). It is quite boring though.<p>[1]: <a href="https:&#x2F;&#x2F;boxyhq.com&#x2F;docs&#x2F;jackson&#x2F;overview" rel="nofollow">https:&#x2F;&#x2F;boxyhq.com&#x2F;docs&#x2F;jackson&#x2F;overview</a>
yagami_takayuki10 months ago
What language&#x2F;framework are you using? Typically you would implement your own authentication for learning the nuts and bolts of auth, but never for a production&#x2F;live system on the web.<p>You would either use something like Firebase Auth or the built-in one that comes with your framework of choice. Identity in .NET core for example.<p>On the topic of auth, and as an aside, wondering if anyone has used a UUID + API key combination to do auth instead of JWT&#x2F;cookies?
评论 #41013934 未加载
评论 #41013014 未加载
mhitza10 months ago
Yes, multiple times. But if you&#x27;d like to build an MVP you can&#x27;t go wrong with a SaaS auth service to get you started and transition to something else.<p>Even better nowadays, there are multiple SaaS&#x2F;starter kits you can use (most are paid) that remove all these chores and you can get down to your domain flow.
评论 #41015071 未加载
illuminant10 months ago
Yes. On login issue a single session auth token to be stored in the header and passed for all future API requests.<p>You should consider one of the many frameworks that handle this sort of thing for you (every language has them.)<p>It is unclear from your comment how you might be helped.
pkulak10 months ago
Oh yeah. I built the oauth 2 stack at my company. Just read through the spec and made sure I did everything, and was obviously very careful.<p>It was pretty boring and grinding. For a personal site, I’d use something off the shelf for sure.