Answer the question
In order to leave comments, you need to log in
How does password authorization work in web applications?
I'm starting to learn web development from the backend side.
Please tell us in a nutshell how authorization works in web applications? Or give a good link...
The situation is something like this:
Answer the question
In order to leave comments, you need to log in
Usually separate sessions and authorization:
Session . To implement a session, the server, on the first connection with the client, can generate some random token and set it in cookies. It is important here that cookies must be transmitted over a secure channel (HTTPS). This way you can save some session information in the database or in the cookies themselves, but then you need to sign the cookies so that the user cannot change them.
In any case, the server will store information about active sessions in the database.
You can sign cookies, for example, by adding some HMAC in addition to the information you need .
Authorization. The server never stores passwords. The database stores the login and password hash (actually not). For authorization, the user sends a login and password (HTTPS). The server calculates a hash from the password and, if it matches, the session is marked as authorized.
Salt . Now let's imagine that you actually store the username and password hash in a table:
login | pass_hash
------+----------
vasya | 4B32E1C...
hash(pass + salt)
, .login | salt | hash
------+--------+-----
vasya | 4B3... | 2A3B9...
Password authentication is the century before last.
In the same article to which you gave a link, please pay attention to the "Authentication by tokens" section.
VKontakte, Facebook, Yandex, Google, Mail.ru, etc. - choose an account provider to your liking and you do not need to worry about storing and transferring passwords, and users - with inventing these passwords, forgetting them, restoring them, entering from the keyboard and other hemorrhoids.
Type in the search engine: oauth <my favorite provider>, and get detailed instructions on how to implement it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question