Live data from Hacker News

Has anyone built their own authentication system?

news.ycombinator.com

1–10 of 26 posts

Has anyone built their own authentication system?

#1
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.

Re: Has anyone built their own authentication system?

#2
What language/framework are you using? Typically you would implement your own authentication for learning the nuts and bolts of auth, but never for a production/live system on the web.

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.

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/cookies?

Re: Has anyone built their own authentication system?

#3

What language/framework are you using? Typically you would implement your own authentication for learning the nuts and bolts of auth, but never for a production/live system on the web. 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. On the topic of auth, and as an aside, wondering if anyone has used a UUID + API key com…

ok, i was trying to do this for production. I am switching over to firebase but it's not working well with my client-server-architecture

Re: Has anyone built their own authentication system?

#4
post #3

What language/framework are you using? Typically you would implement your own authentication for learning the nuts and bolts of auth, but never for a production/live system on the web. 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. On the topic of auth, and as an aside, wondering if anyone has used a UUID + API key com…

ok, i was trying to do this for production. I am switching over to firebase but it's not working well with my client-server-architecture

Ah I see, most frontend frameworks have libraries that work with firebase auth. If you use an MVC like rails or .NET core MVC etc, you can use Firebase auth from a CDN and put it in script tags along with JS to work with the library.

Re: Has anyone built their own authentication system?

#5
Yes. On login issue a single session auth token to be stored in the header and passed for all future API requests.

You should consider one of the many frameworks that handle this sort of thing for you (every language has them.)

It is unclear from your comment how you might be helped.

Re: Has anyone built their own authentication system?

#6

What language/framework are you using? Typically you would implement your own authentication for learning the nuts and bolts of auth, but never for a production/live system on the web. 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. On the topic of auth, and as an aside, wondering if anyone has used a UUID + API key com…

Why never for a live system?

Store users with an username/email and scrypt-encrypted password.

On login, pull the encrypted password where username = $1. Compare. If valid, create a session id (fill 16 bytes with a cryptographically secure random number generator and encode it), store it that in the db along the user_id and some expiration time.

You now have a session_id -> user_id mapping which can.

Re: Has anyone built their own authentication system?

#7
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

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.

Re: Has anyone built their own authentication system?

#8
Yes, several. This is going to be a controversial one... but it isn't nearly as difficult as people make it seem. You shouldn'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't that difficult.

Personally I think the problem is we are being sold so many 'conveniences'/solutions these days. They want you to think you cannot safely do it yourself, and on top of that, often times it's actually more difficult just to learn how to use whatever API the convenience that's being sold to us, uses.

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/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.

Re: Has anyone built their own authentication system?

#9
post #8

Yes, several. This is going to be a controversial one... but it isn't nearly as difficult as people make it seem. You shouldn'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't that difficult. Personally I think the prob…

This has been my experience as well. I started with tools like supabase and appwrite and after spending so much time fiddling with their APIs, decided to do as this commenter suggested and found it wasn't as difficult as I was led to think.
Post reply on HN