AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML Tutorial

Send forgot password by mail or message in PHP

Free Scripts » Send forgot password by mail or message in PHP

The feature of recovering passwords is essential for a login system. It helps the user to update the password of his account if he has forgotten it. Using the link to recover password, a user can easily reset their password to the system. In this tutorial I will show you how to implement the typical "I forgot my password" by means of a PHP script that will send an email to the user.

Send forgot password by mail or message in PHP

Current Password:

New Password:

Confirm Password:


 

Creation of the database

To store all the data about the user, we must have a users table in the MySQL DB. Now, we are going to add a column called forgot_pass_identity to the users table.

CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`last_name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`phone` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`forgot_pass_identity` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
`status` enum('1','0') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Tags: simple forgot password code in php mysqli, send reset password link email php, forgot password code in php github, login-signup-with-forgot-password-in-php, forgot password in php using phpmailer, forgot password in php, password reset php, php password reset token

 

Creating the Config File

Here we can configure the connection with the MySQL server as:

Hostname
MySQL user
MySQL password
Database.
You can also configure the time zone in which the system will work.

Let's create a file named "database.php" and put the following code inside it.

Example database.php
<?php
$servername='localhost';
$username='root';
$password='';
$dbname = "crud";
$conn=mysqli_connect($servername,$username,$password,"$dbname");
if(!$conn){
die('Could not Connect My Sql:' .mysql_error());
}
?>

In this file we are including the file "config.php" that is responsible for establishing the connection with the database using MySQLi.

 

Password reset form (resetPassword.php)

The script loads when the user clicks the reset password link in the email. Once inside, a form will appear to update the account password, which will be sent to the userAccount.php file with the resetSubmit request.

Example

<?php
session_start();
include_once 'database.php';
if(isset($_POST['submit']))
{
$user_id = $_POST['user_id'];
$result = mysqli_query($conn,"SELECT * FROM user_details where user_id='" . $_POST['user_id'] . "'");
$row = mysqli_fetch_assoc($result);
$fetch_user_id=$row['user_id'];
$email_id=$row['email_id'];
$password=$row['password'];
if($user_id==$fetch_user_id) {
$to = $email_id;
$subject = "Password";
$txt = "Your password is : $password.";
$headers = "From: password@agernic.com" . "\r\n" .
"CC: somebodyelse@example.com";
mail($to,$subject,$txt,$headers);
}
else{
echo 'invalid userid';
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
input{
border:1px solid olive;
border-radius:5px;
}
h1{
color:darkgreen;
font-size:22px;
text-align:center;
}

</style>
</head>
<body>
<h1>Forgot Password<h1>
<form action='' method='post'>
<table cellspacing='5' align='center'>
<tr><td>user id:</td><td><input type='text' name='user_id'/></td></tr>
<tr><td></td><td><input type='submit' name='submit' value='Submit'/></td></tr>
</table>
</form>
</body>
</html>

 



simple forgot password code in php mysqli, send reset password link email php, forgot password code in php github, login-signup-with-forgot-password-in-php, forgot password in php using phpmailer, forgot password in php, password reset php, php password reset token
Send forgot password by mail or message in PHP - free scripts

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Send forgot password by mail or message ...
PHP MySQL simple login system...
Check for duplicate username live or ema...
How to create simple search engine using...
Diseño de sitio web CSS Layout...
Diseño de caja flexible CSS3...
Botones en CSS...
ID y Clase, Diferencias entre Class e Id...
Esquina redondeada CSS...
Tamaño de caja css box-sizing: border-b...
Alineación CSS...
Altura y Anchura CSS...
Bordes CSS...
Margen CSS...
Relleno CSS...
Modelo de caja CSS...
Tablas CSS...
Listas CSS...
Enlaces CSS...
Texto CSS...