JS to clear cookies

Recently, the new system development uses cookies to store user information and uses DES encryption

Tools are as follows:

It is better to encrypt the information stored in the browser. Although there are many online decryption tools, encryption is still recommended

Now let's get to the point. How to clear cookies?

Before we talk about this, how do we use js to get cookies?

Cookies are usually encrypted. If the stored cookie is a string, how to decrypt it?

For example, I use DES encryption and decryption. I get it through Ajax and parse it?

The code is as follows:

JS code:

Java code:

How do I clear cookies?

The code is as follows:

I use cookies to store user information, and the natural logoff function also uses the method of clearing cookies

Firstly, cookies have the following advantages and disadvantages:

advantage:

(1) Configurable expiration rules cookies can expire at the end of a browser session, or they can exist indefinitely on the client computer, depending on the client's expiration rules.

(2) No server resource is required. Cookies are stored on the client and read by the server after sending.

(3) Simplicity cookie is a lightweight text-based structure that contains simple key value pairs.

(4) data persistence although the duration of cookies on the client computer depends on the cookie expiration processing and user intervention on the client, cookies are usually the data retention form with the longest duration on the client.

Disadvantages:

(1) the size is limited. Most browsers limit the size of cookies to 4096 bytes, although it is more and more common to support the size of cookies of 8192 bytes in today's new browser and client device versions.

(2) the user is configured to disable. Some users disable the ability of the browser or client device to receive cookies, so this function is limited.

(3) potential security risks cookies may be tampered with. Users may manipulate cookies on their computers, which means that it may pose a potential risk to security or cause applications that rely on cookies to fail. In addition, although cookies can only be accessed by the domain that sends them to the client, hackers have historically found ways to access cookies from other domains on the user's computer. You can encrypt and decrypt cookies manually, but this requires additional encoding and affects the performance of the application because encryption and decryption take some time.

Specifically, why should cookies be used in combination with business needs.

Why do I use cookies? Instead of sessions, sessions are stored on the server side, which is not global. With more and more users, each user has a corresponding session. For the server, there is no small concurrency.

Using cookies, although there are security risks, cookies are global. They are the only cookie in the world. Just store the user's key information, such as ID or user name, so that I can get it on every page. In this way, the effect of intercepting illegal login is also very good, and it virtually reduces a lot of concurrency. Of course, for the time being, for me, using cookies is no longer to build an interceptor filter in order to obtain a session. It really feels like a young man's head is white and empty!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>