Home > Web Front-end > Vue.js > What is the token in vue?

What is the token in vue?

WBOY
Release: 2022-03-23 15:42:28
Original
5140 people have browsed it

In vue, token means "token", which is a string generated by the server and an identifier for the client to make a request; when the user logs in for the first time, the server generates a token and Return to the client. In the future, the client only needs to bring the token to request data, without using the user name and password.

What is the token in vue?

The operating environment of this article: Windows 10 system, Vue version 2.9.6, DELL G3 computer.

What is the token in vue

1. What is the token

Token means "token", which is the server side The generated string serves as an identifier for the client to make a request. When the user logs in for the first time, the server generates a token and returns the token to the client. In the future, the client only needs to bring this token to request data, without bringing in the user name and password again.

The composition of a simple token; uid (the user's unique identity), time (the timestamp of the current time), sign (signature, the first few digits of the token are compressed into sixteen characters of a certain length using a hash algorithm) Hexadecimal string. To prevent token leakage).

2. The role of token

1. Prevent repeated submission of forms: The main idea is that when the client initializes (usually when just entering the page) Call the back-end code, the back-end code generates a token, returns it to the client, and the client stores the token (you can use a hidden field in the Form form at the front desk to store this Token, or you can use cookies), and then send the request (request) Compare the token in with the token in (session)

2. Used for authentication:

(1) Overview of identity authentication

Since HTTP is a Stateful protocol, it doesn't know who is accessing our application. The user is regarded as the client here. The client uses the username and password to pass the authentication. However, the next time the client sends a request, it must be verified again.

The general solution is: when the user requests to log in, if there is no problem, generate a record on the server. In this record, you can explain who the logged in user is, and then send the id of this record. Give it to the client. After the client receives it, it stores the ID in the cookie. The next time the user sends a request to the server again, he can bring this cookie with him. In this way, the server will verify the information in the cookie to see if it can Find the corresponding record here on the server. If possible, it means that the user has passed the authentication, and the data requested by the user will be returned to the client.

The process described above is to use session, and the id value is sessionid. We need to store the sessions generated for users on the server side. These sessions will be stored in memory, disk, or database.

[Related recommendations: "vue.js Tutorial"]

The above is the detailed content of What is the token in vue?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
vue
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template