๐—Ÿ๐—ฒ๐˜€๐˜€๐—ผ๐—ป๐˜€ ๐—ข๐—ป ๐—”๐˜‚๐˜๐—ต๐—ฒ๐—ป๐˜๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—”๐—ป๐—ฑ ๐—”๐˜‚๐˜๐—ต๐—ผ๐—ฟ๐—ถ๐˜‡๐—ฎ๐˜๐—ถ๐—ผ๐—ป

I started my engineering career with total freedom. I tried many tools. I lacked a mentor. I built a bad login system.

Here is what I did wrong. Here is how you should do it.

I used session variables. This fails when you add more servers. A load balancer sends you to different servers. Your session stays on one server. You lose access.

I used MD5 for passwords. I used HTTP. This was a mistake.

I made my own token system. I stored tokens in a database.

Do not reinvent the wheel. Use proven tools.

Use BCrypt for passwords. It uses a salt and a cost factor. This stops fast attacks. Add a pepper. This is a secret key outside your database.

Use JWT for tokens. It is signed and stateless.

Stop using local storage for tokens. Scripts steal them. Use secure cookies.

Security is not about being clever. Use well-proven solutions.

Ask these questions first:

Source: https://dev.to/jmnovelovargas/learnings-about-authentication-and-authorization-hjb