Password reset concept in php - Mostlikers

18 July, 2013

Password reset concept in php

This concept based on login user reset forget password. Sometime use forget the login password  that time user send  request through  admin .the admin generate some authentication code send email on request user email id . The user can get the authentication code and again login to provide new password. So I went to work on making a simple php code it was easy to generate authentication code and send email to login user easily reset password.



View code                Download


This concept include required on 2 page send forget password mail user and reset password on user page 

Database

   CREATE TABLE `signup` (
  `username` VARCHAR( 25 ) NOT NULL ,
  `email` VARCHAR( 25 ) NOT NULL , 
  `password` VARCHAR( 25 ) NOT NULL,
`forget` VARCHAR( 25 ) NOT NULL
  ) 
  INSERT INTO users VALUES ('user', 'sample@example.com', '123456', '');

Send mail.php

First get the login user email id check the mail available on database and create random number code to store variable $i=rand(); its work on when user given mail id automatically this code generate random number update on database.

<?php
  if(isset($_POST['submit'])!="")
  {  
    $username=mysql_real_escape_string($_POST['username']);
    $i=rand(); // this code create some random number 
    $forg=$i+-17;
    $password_check=mysql_query("select * from signup where email='$username'");
    $pwd_check=mysql_num_rows($password_check);
    
      if($pwd_check)
      {
      $search=mysql_query("update signup set forget='$forg' where email='$username'");
      
      
      if($search)
        {
        
        $to = $_POST['username']; 
        $from = "mostlikers@gmail.com"; 
        $subject = "login Forget password";
        //begin of HTML message 
        $message= "Hello &nbsp;" .$username." <br/><br/><br/>
        A request to reset the password for your account has been made at <a href='http://karthickinfotech.blogspot.in/'>Mostlikers</a>.<br/><br/>   
        &nbsp; Your Account confirm code is &nbsp;:&nbsp;".$forg; 
        
        //end of message 
        $headers  = "From: $from\r\n"; 
        $headers .= "Content-type: text/html\r\n";      
        // now lets send the email. 
        mail($to, $subject, $message, $headers);    
        
        $email_error="<span style=color:red; font-size:16px;><b>Check your mail and get the confirm code</b></span>";
        
        }
      else
        {
        $email_error="<span style=color:red; font-size:16px;><b>Your server can't support SMTP</b></span>";
        
        }
      
      }
      
      else
        {
        $email_error="<span style=color:red; font-size:16px;><b>Your Email is not Found in Database</b></span>";
        
        }
  }
  
  ?>

HTML


<form class="form-wrapper"  method="post"> 
<h1> Password concept in php</h1>
<p><strong>Enter your Email ID &nbsp;&nbsp;</strong>
<input type="email" title="email"  name="username" placeholder="Enter your Email"  required="required" ></p>
<p align="center"><input type="submit" value="Send mail" name="submit" class="submit" id="submit"></p>
<p align="center"><?php echo $email_error; ?></p>
</form>

Password reset.php

Authentication code send mail on user now copy and paste the confirm code field if code is matching on database given new password is update

<?php
if(isset($_POST['submit2']))
{
  $username=mysql_real_escape_string($_POST['username']);
  $code=mysql_real_escape_string($_POST['code']);
  $newpass=mysql_real_escape_string($_POST['newpass']); 
  $searchs=mysql_query("select * from `signup` where email='$username' and forget='$code'");
  $result=mysql_num_rows($searchs);
  if($result)
  { 
  $update1=mysql_query("update `signup` set password='$newpass' where email='$username'");
  if($update1)
  {
     $login5="<span style=color:red; font-size:16px;><b>password update successfully</b></span>";
  }
  
  else
  {
      die(mysql_error());
  }
  
  }

   else
   {
       $login5="<span style=color:red; font-size:16px;><b>Invalid user your request not matched</b></span>";
   }
  } 
?>

HTML

<form class="form-wrapper"  method="post"> 
<h2>Forget Password concept in php</h2>
<p><strong>Enter your Email</strong><br />
<input type="email" title="email" name="username"  placeholder="Enter your Email" required="required" ></p>
<p><strong>Confirm code</strong><br />                  
<input type="text" title="code" name="code"  placeholder="Enter send authentication code" required="required"  /></p>
<p><strong>Enter new Password</strong><br />
<input type="password" title="password" name="newpass"  placeholder="Enter new password"  required="required" > </p>
<p><input type="submit" title="submit" value="Change password" name="submit2"></p>
<p><?php echo $login5; ?></p>
</form>


This coding mail send concept work on online can’t mail send to loalhost why I make generate authentication code many site password will store an encryption mode so they don’t know about password so we will use on authentication code to update the password.

No comments:

Post a Comment