Hi everybody, Today I am talking about Forgot Password Using Ajax, jQuery and PHP. It is a very easy script. We use it for almost every website we build. Lets build forgot password script
Step 1 : In step 1 we create a database table for user where we store user information along with his/her password

user_id int(11) NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
email_address varchar(255) NOT NULL,
PRIMARY KEY (user_id)

Then we put some data to user table. For your application you already have your user information table with user data. Here I save password using md5
INSERT INTO user (user_id, username, password, email_address) VALUES
(1, ‘abhijitpal’, ‘e31f23e05a7886f02f834273ea5788c0’, ‘abhijit@technokrats.in’),
(2, ‘technokrats’, ‘fcea920f7412b5da7be0cf42b8c93759’, ‘techno@technokrats.in’),
(3, ‘phplover’, ‘fcea920f7412b5da7be0cf42b8c93759’, ‘abcd@technokrats.in’),
(4, ‘headadmin’, ’34aa691953f223d89bdd02cbcfdf534e’, ‘admin@technokrats.in’);

Step2: Here I create a forgot password form where user put their email address. I create index.php for that view.

Step 3: Now I create style.css for styling my form

Step 4: Now I create a getpassword.js file. When user give their email address and click “Get Password” button. This file will take the email address from input box, validate the email address and send it to another php file using ajax post request.

Step 5: This file will take the email address from js file and change password for this email address and also mail the password. After successfull complete or unsuccessfull, a message will send to js file and this message will show to the browser.

Spread the love
Forgot password script using Ajax, jQuery and PHP
  • Sandeep Mishra

    I used the code and got error “Email invalid” every time on putting correct email. Echoing email id also not printing on the submitted page.
    Please assist as soon as possible.