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.

$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.

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

Password recovery page </h2>

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

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

        $pass  =  $rows['password'];
        echo "<b><p 

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

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

<title>Password recovery page</title>
<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" />

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

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

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

</marquee> </p>


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.