Php+jquery+mysql Retrieve password----thinkphp

Source: Internet
Author: User
Tags md5 encryption jquery library

Recently used thinkphp to do a mailbox retrieve password function, after encountering n bug finally made, the following share the mailbox retrieve password function realization:

The mailbox recovery password is actually the process of resetting the password after the user has authenticated, and the general developer will generate a new password through the program after verifying the user information.

Either generate a specific link and send the message to the user's mailbox, and the user resets the new password from the Reset password module linked to the Web site of the mailbox.

The general steps are:

1. Form enter the mailbox when registering;
2. Verify that the user mailbox is correct, if the user mailbox does not exist in the user table of the site, then prompt the user mailbox is not registered;
3. Send the message, if the user mailbox does exist in the user table, then combine the string used to validate the user information and construct the URL to send to the user's mailbox;
4. User login mailbox to receive mail, click the URL link to the website verification program;
5. The website program queries the local user table through the string requested by the user, which is more accurate than the user information;
6. If correct, go to the Reset Password page and reset the new password, otherwise the user is prompted to verify that it is invalid.

First of all, we must first write a retrieve Password view page, the sample code is as follows:

View interface Display

After this is done, the next step is to verify the user entered the mailbox (because the password is retrieved by sending a message to the user to implement the reset password, so the user at the registration of the mailbox is required)

jquery mailbox Verification, code:

The jquery code used above is convenient and concise to complete the front-end interaction, if you have a certain jquery basis, the above code at a glance, not much explanation.
Of course, do not forget to load the jquery library file on the page, if the validation rule found that the function is not implemented, the 80% is jquery or other file loading path is wrong cause the necessary files are not loaded (this is a profound lesson, I just started to careless)

Then through Ajax to send the user input mailbox to the controller to verify that the e-mail exists in the user table, if any, then read the user information, the user ID, user name and password for MD5 encryption to generate a special string as a code to retrieve the password, and then construct the URL.

At the same time, in order to control the timeliness of the URL link, the user will be logged to submit the operation time to retrieve the password action, and finally call the Mail send class to send mail to the user mailbox.

Code

The Send mailbox functions are as follows:

There is an SMTP class inside, which encapsulates the function more, I can not, well, this time your mailbox will receive a password to retrieve the message, the message content has a URL link, click on the link to their own written page to verify the mailbox.

E-mail verification to this is finished, this email verification is my reference link http://www.helloweba.com/ View-blog-229.html do, indeed very good, although some places are always out of the bug but fortunately, if the password to find the interest can refer to, want to source code can go directly to the original article, are similar. There is an SMTP package provided in the original article, and I also downloaded it there. Finish

Php+jquery+mysql Retrieve password----thinkphp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.