当前位置:网站首页>FAQs and answers to the imitation Niuke technology blog project (I)
FAQs and answers to the imitation Niuke technology blog project (I)
2022-07-06 13:37:00 【Li bohuan】
1. How to realize the registration of the project
User registration for developers is to insert a new user data into the database table . In our project, it is in user Insert a new piece of data into the table , We can develop according to the following three requests realized by the registration function
We develop every request by Dao——>sevice——controller layer
Before inserting data , Null value verification will be performed on the data , Verify the account and mailbox repeatedly , Use map To store error messages , If controller I got it on the second floor map If it is blank, it means the registration result , Carry out subsequent activation processing . When inserting data , The password will be salted , In the use of MD5 The algorithm encrypts , And then store it in the database , Initial data Status Set to 0, Invalid representation , Activation processing is required .
Activate logic :
2. How does the project realize user uniqueness verification
Creating MySQL Table time , Use unqiue Keyword guarantees user name username Uniqueness of fields . in addition , Repeat verification when registering users , If the user already exists , Cannot register .
3. Project deployment
Not deployed
4. Why should we choose SpringBoot
use SpringBoot To simplify project development ,Springboot Have the following advantages :
One 、 Independent operation
Spring Boot And it's embedded with all kinds of servlet Containers ,Tomcat、Jetty etc. , It's no longer necessary to play war Package deployed to container ,Spring Boot Just type an executable jar The package can run independently , All dependency packages are in one jar In bag .
Two 、 Simplified configuration
spring-boot-starter-web Initiators automatically depend on other components , Jane is missing maven Configuration of .
3、 ... and 、 Automatic configuration
Spring Boot According to the current class path 、jar Package to automatically configure bean, If you add a spring-boot-starter-web The starter can have web The function of , No other configuration required .
Four 、 No code generation and XML To configure
Spring Boot No code generated during configuration , No need XML Configuration files can do all the configuration work , All this is done with the help of conditional annotation , This is also Spring4.x One of the core functions of .
5. Where is the login status saved
Save in user credential table , Include users id, User credentials , User status and expiration time , For user credential table is 0 It works 1 Invalid . Verify whether the account password is empty when logging in , Or whether the password is wrong , If there is no error, generate login credentials , The code is as follows
6. How to display the login page after the user logs in
Users will log in with ticket by key, And the actual ticket by value Create a cookie Save to browser , Then the server queries in the user credential table according to the user credentials user The information is encapsulated in a template and then returned to the browser . The code and process are shown in the figure below
This process exists when every user logs in , So we need interceptors to deal with . At the same time, for the server , At the same time, there may be a large number of browser requests , So thread safety is also involved here .
Interceptor :1. Custom interceptors 2. Configure interceptors
Verify the user first
after controller after , Return to the interceptor , The interceptor then stores the user information model
Custom interceptors need to be implemented HandlerInterceptor, Then rewrite preHandle(controller Pre execution ),postHandle(controller After execution ), as well as afterCompletion( Execute after template parsing )
Configure interceptors : Need to achieve WebMvcConfigurer Interface , Then rewrite addInterceptors Method , Exclude blocking static pages .
use ThreadLocal To save user information , Ensure thread safety
ThreadLocal Source code :
As you can see from the code above ,ThreadLocal set When assigning values, the current thread will be obtained first thread, And get the thread In thread ThreadLocalMap attribute . If map Property is not empty , Then directly update value value , If map It's empty , Then instantiate threadLocalMap, And will value Value initialization
ThreadLocalMap yes ThreadLocal The inner static class of , And its composition mainly uses Entry To save the data , And it's an inherited weak reference . stay Entry For internal use ThreadLocal As key, Use We set up value As value.
Through the current thread object getMap() Method to get ThreadMap object And then put the current ThreadLocal Object as key Value deposit map This ensures that resources are shared within threads and that different threads are independent
7.md5 Do you know the principle ? Is it safe? ? Reversible ?
Can be MD5 The algorithm is regarded as a machine , Anything on the computer ( character string , picture , Video etc. ) If it is thrown in, it will output a length of 128 Bit MD5 value .
The input message is the same , The result will always be the same , Different news , The result is different .MD5 Principle introduction :MD5 With 512 Bit grouping to process the input information , And each group is divided into 16 individual 32 Group the seats , After a series of treatment , The output of the algorithm consists of four 32 Bit grouping composition , Put these four 32 After the concatenation of bit groups, a 128 Bit hash value .
MD5 The security of : It is generally believed that MD5 It's safe , Because the time of brute force cracking is unacceptable to ordinary people . In fact, if you put the user's password MD5 After processing, it is stored in the database , It's not safe . Because the user's password is relatively short , And many users use birthday passwords , Phone number , Id card number , Phone numbers and so on . Or use some commonly used auspicious numbers , Or an English word . If I put the commonly used password first MD5 Handle , Store the data , And then talk to your MD5 The results match , Then I may get the plaintext . So in our project , The user password will be salted ( Add a random string at the end of the password ) And then we can move on MD5 Encrypt and store in the database .
MD5 Is it reversible : Irreversible , as a result of MD5 Is a hash function , It uses hash Algorithm , In the process of calculation, part of the original information is lost .
边栏推荐
- 【九阳神功】2020复旦大学应用统计真题+解析
- Voir ui plus version 1.3.1 pour améliorer l'expérience Typescript
- 仿牛客技术博客项目常见问题及解答(一)
- 西安电子科技大学22学年上学期《基础实验》试题及答案
- Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology
- Mortal immortal cultivation pointer-2
- 魏牌:产品叫好声一片,但为何销量还是受挫
- Implement queue with stack
- Rich Shenzhen people and renting Shenzhen people
- C语言入门指南
猜你喜欢
凡人修仙学指针-2
一段用蜂鸣器编的音乐(成都)
优先队列PriorityQueue (大根堆/小根堆/TopK问题)
Mortal immortal cultivation pointer-2
1.C语言初阶练习题(1)
Redis的两种持久化机制RDB和AOF的原理和优缺点
3.输入和输出函数(printf、scanf、getchar和putchar)
1.初识C语言(1)
Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
2. Preliminary exercises of C language (2)
随机推荐
MySQL limit x, -1 doesn't work, -1 does not work, and an error is reported
Set container
Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited
Rich Shenzhen people and renting Shenzhen people
为什么要使用Redis
C language to achieve mine sweeping game (full version)
C语言实现扫雷游戏(完整版)
2. C language matrix multiplication
魏牌:产品叫好声一片,但为何销量还是受挫
Application architecture of large live broadcast platform
[the Nine Yang Manual] 2020 Fudan University Applied Statistics real problem + analysis
Data manipulation language (DML)
一段用蜂鸣器编的音乐(成都)
仿牛客技术博客项目常见问题及解答(二)
Share a website to improve your Aesthetics
Mortal immortal cultivation pointer-1
[while your roommate plays games, let's see a problem]
Database operation of tyut Taiyuan University of technology 2022 database
自定义RPC项目——常见问题及详解(注册中心)
关于双亲委派机制和类加载的过程