PHP Retrieve password mechanism process

Source: Internet
Author: User
Tags md5 php file php code trim

The author of the previous paragraph of a project, which contains a user registration system, using the password to retrieve the function, simple to clean up, write some experience.

First, let's assume that you already have a user registration system. The user table may be as follows:

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

The focus of the discussion is not database design, we mainly talk about password retrieve.

We can choose the password to retrieve the program may have the following several:
1. User preset to retrieve the password problem, and provide the answer password.
2. Users to retrieve the password via email
..........................

The first scenario may be a good solution, but we don't choose this one, and the reasons for this are not in this discussion. We use the second scheme as the main object of discussion.

So let's get started.

The benefits of the second option are:
1. The registered user must provide the correct mailbox, or you will not be able to use the password reset feature provided by the system.
2. Must be confirmed by the user through the mailbox.
This may be a good thing for the business. Companies are always trying to get the real details of their users for targeted mailing list services. This is also one of the main reasons for this development user to ask for this.

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

When the user clicks to find the password, we provide an input form. Let the user enter the username (if login fails, we can fill 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 passed through the Get method and sending it out.

The code may be as follows:
PHP Code:
<?php
/**
* Let's say you've configured your SQL information in the config.inc.php file, mail information
*/
Require_once (' config.inc.php ');

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

/**
* First we execute the query to get the relevant information of this user
* Don't you tell me you don't know how $_post[' username '] got it, if so, I'm depressed you.
* I have used the ADODB class and have declared it in the configuration 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've got some things we need, so it looks like we're going to have to do the next step.
* Now let's create a string that passes through the MD5 code, don't ask why, I'll tell you later.
*/

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

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.