Create Login and Signup form with Forget Password using PHP
Author:
Views: 1331


Few days ago we post and tutorial on login and signup procedure and today I am going to write an other element of that login procedure for PHP Developers which is recover your password using email verification with encrypted key. This article demo is merged with login & signup demo.

index.php

<?php

if($_POST['action']=="password")

{

    $email      = mysqli_real_escape_string($connection,$_POST['email']);

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) // Validate email address

    {

        $message =  "Invalid email address please type a valid email!!";

    }

    else

    {

        $query = "SELECT id FROM users where email='".$email."'";

        $result = mysqli_query($connection,$query);

        $Results = mysqli_fetch_array($result);



        if(count($Results)>=1)

        {

            $encrypt = md5(1290*3+$Results['id']);

            $message = "Your password reset link send to your e-mail address.";

            $to=$email;

            $subject="Forget Password";

            $from = 'info@phpgang.com';

            $body='Hi, <br/> <br/>Your Membership ID is '.$Results['id'].' <br><br>Click here to reset your password http://demo.phpgang.com/login-signup-in-php/reset.php?encrypt='.$encrypt.'&action=reset   <br/> <br/>--<br>PHPGang.com<br>Solve your problems.';

            $headers = "From: " . strip_tags($from) . "
";

            $headers .= "Reply-To: ". strip_tags($from) . "
";

            $headers .= "MIME-Version: 1.0
";

            $headers .= "Content-Type: text/html; charset=ISO-8859-1
";



            mail($to,$subject,$body,$headers);

        }

        else

        {

            $message = "Account not found please signup now!!";

        }

    }

}

?>

SQL

CREATE TABLE `users11` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(240) NOT NULL,

  `email` varchar(240) NOT NULL,

  `password` varchar(240) NOT NULL,

  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP

  PRIMARY KEY (`id`)

) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CSS

input[type=text]

{

  border: 1px solid #ccc;

  border-radius: 3px;

  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);

  width:200px;

  min-height: 28px;

  padding: 4px 20px 4px 8px;

  font-size: 12px;

  -moz-transition: all .2s linear;

  -webkit-transition: all .2s linear;

  transition: all .2s linear;

}

input[type=text]:focus

{

  width: 400px;

  border-color: #51a7e8;

  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1),0 0 5px rgba(81,167,232,0.5);

  outline: none;

}

input[type=password]

{

  border: 1px solid #ccc;

  border-radius: 3px;

  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);

  width:200px;

  min-height: 28px;

  padding: 4px 20px 4px 8px;

  font-size: 12px;

  -moz-transition: all .2s linear;

  -webkit-transition: all .2s linear;

  transition: all .2s linear;

}

input[type=password]:focus

{

  width: 400px;

  border-color: #51a7e8;

  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1),0 0 5px rgba(81,167,232,0.5);

  outline: none;

}