PHP Retrieve password mechanism flow _php Tutorial

Source: Internet
Author: User
The author of the previous paragraph of a project, which contains a user registration system, the use of the password recovery function, simple collation, write some experience.

First, we assume that you already have a user registration system. Where the user table might look like:

CREATE TABLE member (
ID int unsigned NOT NULL auto_incremtnt,
Username ..... .........
Passwords char (+) NOT NULL,
Email varchar (+) NOT NULL,
...................................
);

Now the focus of discussion is not database design, we mainly talk about password retrieval.

The password retrieval scenarios we can choose may include the following:
1. User preset To retrieve password problem, and provide retrieve password answer.
2. User to retrieve password via email
..........................

The first scenario may be a good solution, but we do not choose this one for a variety of reasons, and not in this discussion. We use the second option as the main object of this discussion.

So let's get started.

The benefits of the second scenario are:
1. Registered users must provide the correct mailbox or they will not be able to use the password reset feature provided by the system.
2. Must be confirmed by the user via email.
This may be a good thing for the business. Companies are always struggling to get real-world information about their users for targeted mailing list services. This is also one of the main reasons for this development user requirement to do so.

We may provide a link in the login interface, or provide a link after login fails. Link Name of course you can define your own, I define is: Forget the password, need to retrieve it?

When the user clicks on the password, we will provide a form for input. Let the user enter the user name (if login fails, we can populate the form content with the session). After the user clicks Submit, we start our password reset function flow.

We may create such a file send_reset_pass_mail.php. This file is primarily responsible for generating a string that is passed through the get method and sending it out.

The code might look like this:
PHP Code:
/**
* We assume that you have configured your SQL information in the config.inc.php file, the mail message
*/
Require_once (' config.inc.php ');

/**
* You need a SendMail class to send mail, we also assume that you have configured and can send mail
*/
Require_once (' sendMail.inc.php ');

/**
* First we execute the query, get the relevant information of this user
* You don't tell me you don't know $_post[' username ' How to get, if so, I depressed you.
* I have used the ADODB class and have already declared it in the config file
*/
$username = Trim ($_post[' username ');

$sql = "Select Email,passwords from member where username = '". Trim ($_post[' username ']). "'";
$userInfo = $db->fetchrow ($sql);

$user _pass = $userInfo [' Passwords '];
$user _email = $userInfo [' email '];

/**
* OK, we have everything we need, we have to move on.
* Now let's create a string that has been MD5 and password, don't ask why, I'll tell you later
*/

$x = MD5 ($username. ' '. $passwords);
Now we can send the message to the user. Of course, we also need another password reset program resetuserpass.php
$String = Base64_encode ($username. ".". $x);

http://www.bkjia.com/PHPjc/631885.html www.bkjia.com true http://www.bkjia.com/PHPjc/631885.html techarticle The author of the previous paragraph of a project, which contains a user registration system, the use of the password recovery function, simple collation, write some experience. First, we assume that you already have a ...

  • Related Article

    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.