As one of the three giants of traditional e-commerce (the others are Alibaba and Pinduoduo), the difficulty of Dongzi's interview questions is also average. Generally speaking, it is not as difficult as the other two interviews, and of course the salary is not as high as the other two. Among them, Pinduoduo's salary is the most outrageous, especially in the past few years. I heard that they poached developers from the same industry and offered them salaries that were two to three times their original salaries. It's really abnormal (but I like it). Dongzi's interview questions are as follows: picture Most of the interview questions can be answered on my website (www.javacn.site), so I won’t go into details here. Today we will only talk about: What are the differences between Cookie, Session and Token? 1. What are the differences between Cookie, Session and Token?Cookies, Sessions, and Tokens are usually technologies used to save user login information, but there are big differences between the three. Simply put, Cookies are suitable for simple state management, Sessions are suitable for scenarios where user sensitive information needs to be protected, and Tokens are suitable for state-independent authentication and authorization. Analysis of Token state independence: In the traditional session-based authentication method, the server needs to save the user's session state in the backend and manage the session through the Session ID. The Token mechanism does not need to save any user status information on the server. When the login is successful, the server only needs to generate a unique Token value through a certain algorithm, and then send this Token to the client for storage (stored in localStorage or sessionStorage). Note that the server does not store this Token value at this time. The server only verifies but does not save this Token. This is called "state independence". This can reduce the burden of the server to store and manage the session state, so it is more suitable for large systems and distributed systems. Specifically, the differences between Cookie, Session and Token are as follows:
2.What is the relationship between Cookie and Session?To be precise, the implementation of Cookie has nothing to do with Session, but the implementation of Session requires the help of Cookie. The implementation process of the Session mechanism is as follows:
So by default, the Session uses Cookies to complete the transmission of identity identification, so that the server can associate the Session ID with the saved session information to find a specific logged-in user. Therefore, by default, the Session mechanism relies on Cookies. 3. Can Session still be used after disabling Cookies?From the above, we know that by default, the Session mechanism is implemented by relying on Cookies. So does it mean that after disabling Cookies, the Session mechanism will no longer be usable? Actually, it is not. In addition to the default, we can use cookies to pass the Session ID, we can use some special means to pass the Session ID by ourselves, so as to get rid of the situation where the Session cannot be used after disabling cookies, such as the following two implementation methods:
The above methods can pass the Session ID to the server (although it is a bit troublesome). Then on the server, we can obtain and map the Session ID passed above. In this way, the work of passing and matching the logged-in user is manually completed, and the Session mechanism can continue to be used. summaryCookies, Sessions, and Tokens are usually used to save user login information, but there are big differences between the three: Cookies are suitable for simple state management, Sessions are suitable for scenarios where sensitive user information needs to be protected, and Tokens are suitable for state-independent authentication and authorization. By default, Sessions use the Cookie mechanism to pass Session IDs, but when Cookies are disabled, Session IDs can still be passed using special means, and the Session mechanism can still be used. Tokens do not save session information on the server side, so they are more suitable for large and distributed projects. |
<<: 6G is getting further and further away from us
>>: Analysis of the Art of Communication between Computers
Enterprises are transforming their networks to be...
The "Made in China 2025 Strategy" has e...
Currently, 100M fiber-optic access to homes has b...
As we all know, since the outbreak of the informa...
edgeNAT has released a Double 12 discount plan, v...
[Original article from 51CTO.com] On July 21 and ...
In the world of IoT, wireless communication techn...
The State Council recently issued the "14th ...
The way we commute may have changed over time, bu...
introduction: Hello everyone, I am Xiaozaojun. In...
[[185144]] Riverbed Technology, the application p...
As we all know, in the 5G era, we are greeted by ...
Today, in the telecommunications sector, 5G and I...
The latest news is that BandwagonHost has opened ...