当前位置:网站首页>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 .
边栏推荐
- Solution: warning:tensorflow:gradients do not exist for variables ['deny_1/kernel:0', 'deny_1/bias:0',
- arduino+DS18B20温度传感器(蜂鸣器报警)+LCD1602显示(IIC驱动)
- string
- View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
- 【九阳神功】2022复旦大学应用统计真题+解析
- 受检异常和非受检异常的区别和理解
- View UI plus releases version 1.1.0, supports SSR, supports nuxt, and adds TS declaration files
- [the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
- 仿牛客技术博客项目常见问题及解答(一)
- 优先队列PriorityQueue (大根堆/小根堆/TopK问题)
猜你喜欢
Database operation of tyut Taiyuan University of technology 2022 database
Service ability of Hongmeng harmonyos learning notes to realize cross end communication
1.初识C语言(1)
9. Pointer (upper)
编写程序,模拟现实生活中的交通信号灯。
View UI plus released version 1.2.0 and added image, skeleton and typography components
Change vs theme and set background picture
(ultra detailed onenet TCP protocol access) arduino+esp8266-01s access to the Internet of things platform, upload real-time data collection /tcp transparent transmission (and how to obtain and write L
Questions and answers of "basic experiment" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
Smart classroom solution and mobile teaching concept description
随机推荐
Relational algebra of tyut Taiyuan University of technology 2022 database
Mortal immortal cultivation pointer-1
Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited
MySQL Database Constraints
View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
(超详细二)onenet数据可视化详解,如何用截取数据流绘图
5. Download and use of MSDN
7. Relationship between array, pointer and array
A brief introduction to the database of tyut Taiyuan University of technology in previous years
String abc = new String(“abc“),到底创建了几个对象
Cookie和Session的区别
View UI Plus 发布 1.2.0 版本,新增 Image、Skeleton、Typography组件
[Topic terminator]
2. Preliminary exercises of C language (2)
5月27日杂谈
Change vs theme and set background picture
View UI Plus 發布 1.3.1 版本,增强 TypeScript 使用體驗
优先队列PriorityQueue (大根堆/小根堆/TopK问题)
The latest tank battle 2022 - full development notes-3
1.C语言矩阵加减法