当前位置:网站首页>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 .
边栏推荐
- View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
- [Topic terminator]
- View UI plus released version 1.2.0 and added image, skeleton and typography components
- Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology
- C language to achieve mine sweeping game (full version)
- [modern Chinese history] Chapter V test
- FileInputStream和BufferedInputStream的比较
- 受检异常和非受检异常的区别和理解
- MPLS experiment
- 1.C语言矩阵加减法
猜你喜欢

9.指针(上)

7.数组、指针和数组的关系

6.函数的递归

3. Number guessing game

甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1

1.初识C语言(1)

Data manipulation language (DML)

3.输入和输出函数(printf、scanf、getchar和putchar)

Questions and answers of "basic experiment" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology

3.猜数字游戏
随机推荐
最新坦克大战2022-全程开发笔记-1
【九阳神功】2022复旦大学应用统计真题+解析
这次,彻底搞清楚MySQL索引
强化学习系列(一):基本原理和概念
2. C language matrix multiplication
一段用蜂鸣器编的音乐(成都)
Relational algebra of tyut Taiyuan University of technology 2022 database
优先队列PriorityQueue (大根堆/小根堆/TopK问题)
Introduction and use of redis
7.数组、指针和数组的关系
13 power map
3. C language uses algebraic cofactor to calculate determinant
[the Nine Yang Manual] 2016 Fudan University Applied Statistics real problem + analysis
Conceptual model design of the 2022 database of tyut Taiyuan University of Technology
Set container
MySQL锁总结(全面简洁 + 图文详解)
【九阳神功】2019复旦大学应用统计真题+解析
5. Function recursion exercise
arduino+水位传感器+led显示+蜂鸣器报警
The latest tank battle 2022 full development notes-1