search
HomeJavajavaTutorialMethod implementation based on SpringBoot password retrieval (picture and text)

The content of this article is about the implementation of the SpringBoot password retrieval method (pictures and texts). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

I am working on my own project recently, and one of the functions that everyone knows is to retrieve passwords. I’ll share my approach here, because there are so many pitfalls in the process. So record it.

Used technologies: SpringBoot1.5.6, JPA, SpringSecurity4, MySQL, BootStrap, etc. . .

Password retrieval flow chart:

First of all, let me introduce to you the basic principles of password retrieval:

Next, let’s implement it according to the flow chart. The first step is to click to jump to the password retrieval interface: I use this method. You can feel free to

The password retrieval interface is:

Step 2: Determine whether the entered account is valid

The following is the generated URL link if it exists:

backPassword:

Step 3: Judgment Whether the account exists in the reset table. The reset table is a table that saves URLs (expiration time, sid, account information, etc.)

The purpose of this is: if the data exists and is not deleted, the next time you retrieve the password, 2 data with the same account but different sid will be generated, like this The disadvantage is: I don’t know which URL to return when sending an email, because there are 2 URLs

Step 4: Send the email

Let’s look at it first The following effect:

#The next step is the important part: how to handle the verification link. First we can see that /user/reset_password is a request followed by its parameters, so remember !

We need to write a request, the route is /user/reset_password, and at the same time, we need to allow the request in SpringSecurity. The verification process is as follows: first, compare the sid and userName (that is, the email address) passed from the request with the sid and account in the database, and also compare whether the time is within the validity period of 30 minutes. If these are satisfied It returns true, otherwise false. It should be noted that there is a replacement here where spaces are replaced with numbers. This is because the numbers are automatically converted to spaces when the HTML is passed to the backend. If it is not replaced with numbers, it will always prompt verification failure! ! ! Once true is returned, it means that the verification URL has passed, and it will jump to the password reset interface:

Note: I have no verification here For optimization, there should not be so many if else nests

Release the request route: if not, click the link and it will jump to the login interface

Jump to the reset page. If the passwords we enter twice are inconsistent, the following prompt will appear. I used JS to do the verification:

Of course, for the sake of rigor, we also perform two password verifications in the background. If the inputs are consistent, the information will be updated. If they are inconsistent, an error will be returned.

There is nothing here, just pay attention to using MD5 salt to encrypt the password before saving it to the database, and then save it. Let’s take a look at the effect of entering the correct password twice: the page prompts that the modification is successful and no error is reported in the background. At this time Use the new password to log in

The above is the detailed content of Method implementation based on SpringBoot password retrieval (picture and text). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete
How to properly configure apple-app-site-association file in pagoda nginx to avoid 404 errors?How to properly configure apple-app-site-association file in pagoda nginx to avoid 404 errors?Apr 19, 2025 pm 07:03 PM

How to correctly configure apple-app-site-association file in Baota nginx? Recently, the company's iOS department sent an apple-app-site-association file and...

What are the differences in the classification and implementation methods of the two consistency consensus algorithms?What are the differences in the classification and implementation methods of the two consistency consensus algorithms?Apr 19, 2025 pm 07:00 PM

How to understand the classification and implementation methods of two consistency consensus algorithms? At the protocol level, there has been no new members in the selection of consistency algorithms for many years. ...

What is the difference between IS TRUE and =True query conditions in MySQL?What is the difference between IS TRUE and =True query conditions in MySQL?Apr 19, 2025 pm 06:54 PM

The difference between ISTRUE and =True query conditions in MySQL In MySQL database, when processing Boolean values ​​(Booleans), ISTRUE and =TRUE...

How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling?How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling?Apr 19, 2025 pm 06:51 PM

How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling? Using EasyExcel for Excel...

As a Java programmer, how do you turn to audio and video development? What basic knowledge and resources do you need to learn?As a Java programmer, how do you turn to audio and video development? What basic knowledge and resources do you need to learn?Apr 19, 2025 pm 06:48 PM

How to switch from Java programmers to audio and video development? Learning Paths and Resources Recommendations If you are a Java programmer and are participating in a video project, �...

How to efficiently count the number of node services in MYSQL tree structure and ensure data consistency in Java?How to efficiently count the number of node services in MYSQL tree structure and ensure data consistency in Java?Apr 19, 2025 pm 06:45 PM

How to efficiently count the number of node services in MYSQL tree structure in Java? When using MYSQL database, how to count the number of nodes in the tree structure...

How do newcomers choose Java project management tools for backends: Maven or IntelliJ? Use the Maven that comes with IDEA or an additional download?How do newcomers choose Java project management tools for backends: Maven or IntelliJ? Use the Maven that comes with IDEA or an additional download?Apr 19, 2025 pm 06:42 PM

How do newcomers choose Java project management tools for backends? Newbie who are just starting to learn back-end development often feel confused about choosing project management tools. Special...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment