PHP-MySQL

Password recovery example using php from MySQL

To retrieve the password from your MySQL Database with using PHP script.

Step 1 : Create a table called “users” in your MySQL database with following structure for the same.

Step 2: Create a configuration file called ‘config.php’ which contains connection string and local host / remote server path.

<?php
$connection = mysql_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db('mars_db');
if (!$select_db){
die("Database Selection Failed" . mysql_error());
}
?>

Step 3: Now create a ‘forgotpassword.php’ page with following code in it.

<center>
<h2 style='background-color:skyblue; color:blue'> 

Password recovery page </h2>
<hr>

<?php error_reporting (E_ALL ^ E_NOTICE); ?>

<?php session_start();
include"config.php"; 
if (isset($_POST['username'])){
    $username = $_POST['username'];
    $query="select * from users where 

usernm='$username'";
    $result=mysql_query($query);
    $count=mysql_num_rows($result);
    if($count==1)
    {
        $rows=mysql_fetch_array($result);
        $pass  =  $rows['password'];
        echo "<b><p 

style='background-color:green; color:yellow'>your 

password is::".($pass)."";
        $to = $rows['usernm'];
}
}
?>

<html>
<head>
<title>Password recovery page</title>
</head>
<body>
<form action="" method="post">
        <label> Enter your User Name / Email 

Id : </label>
        <input id="username" type="text" 

name="username" />
        <input id="button" type="submit" 

name="button" value="Submit" />
    </form>

<b><p style='background-color:khaki; 

color:teal'><marquee  onmouseover='stop()' 

onmouseout='start()' > Password recovery demo page 

</marquee> </p>

</body>
</html>

Step 4: Run the program to recover the forgot password.

Step 5: After entering existing user id, the following password is retrieved from your database.

 

SKB