Jump to content

[SOLVED] Help me please! I have trouble in "Forgot Password Scrpt"...


hunter_li

Recommended Posts

I need a Jmail forgot password script, many of our members have forgotten their password. I had some scripts, but it need SMTP service, the virtual-space doesn't support SMTP service ,i can't send password to the member. will you have jmail forgot password script?  help me, thanks.

 

 

 

 

Link to comment
Share on other sites

There you go this will change the users password to a new one.

and show it on the current page......

 

this will ony work if the user nows there current username and email address.......

 

the code will see if the user exists then chage the password with a numiric number

then echo there new details out.....

 

<?php session_start();

// database connection.....

if($_POST['submit']){

$username=$_POST['username'];
$email=$_POST['email'];

$sql="SELECT * from `what_ever` where `userna
me`='$username' AND `email`='$email'";
$sql_result=mysql_query($sql)or die(mysql_error());

while($x=mysql_fetch_assoc($sql_result)){

	if( ($x['username']) && ($x['email']) > 1){

		$new_pass=rand(0,123456);

		$_SESSION['pass']=$new_pass;

		$new_pass=(md5($_POST['new_pass']));

		$sql2="UPDATE `what_ever` set `password`='$new_pass' WHERE
		`username`='$username' AND `email`='$email'";

		$sql2=mysql_query($sql2) or die(mysql_error());


		    	echo "<br><br>

			     Your new ".$x['username']." password <br><b>
			     
			     Username: ".$x['username']." <br><br>
			     Password: ".$_SESSION['new_pass']." <br><br>
			     
			     Please try to remember your new password cheers! <br><br>
                                     or change your password in your members area to a 
                                     easy remembered password";
		}else{

			echo" Sorry we have no record of your username or email <br><br>
			 please join our website <br><br>
			 <a href='join.php'>join now!<a>";
			exit;
		}
              }
               }
?>
<center>
<form method="POST" action="<?php $_SERVER['PHP_SELF'] ?>">
<h1>Password recovery</h1>
<br>
Please provide username:
<br><br>
<input type="text" name="username">
<br><br>
Please provide email address:
<br><br>
<input type="text" name="email">
<br><br>
<input type="submit" value="Send">
</form>
</center>

Link to comment
Share on other sites

thanks redarrow, but it still doesn't work ,what's wrong with it ?

 

code:

 

<?php session_start();

 

$host="localhost"; // Host name

$username="root"; // Mysql username

$password="mypassword"; // Mysql password

$db_name="hunterli"; // Database name

 

 

//Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect to server");

mysql_select_db("$db_name")or die("cannot select DB");

 

if($_POST['submit']){

 

$username=$_POST['username'];

$email=$_POST['email'];

 

$sql="SELECT * FROM tb_users WHERE username='$username' and email='$email'";

$sql_result=mysql_query($sql)or die(mysql_error());

 

while($x=mysql_fetch_assoc($sql_result)){

 

if( ($x['username']) && ($x['email']) > 1){

 

$new_pass=rand(0,123456);

 

$_SESSION['pass']=$new_pass;

 

$new_pass=(md5($_POST['new_pass']));

 

$sql2="UPDATE tb_users set password='$new_pass' WHERE username='$username' AND email='$email'";

 

$sql2=mysql_query($sql2) or die(mysql_error());

 

 

    echo "<br><br>

 

    Your new ".$x['username']." password <br><b>

   

    Username: ".$x['username']." <br><br>

    Password: ".$_SESSION['new_pass']." <br><br>

   

    Please try to remember your new password cheers! <br><br>

                                    or change your password in your members area to a

                                    easy remembered password";

}else{

 

echo" Sorry we have no record of your username or email <br><br>

please join our website <br><br>

<a href='login.php'>join now!<a>";

exit;

}

              }

              }

?>

<center>

<form method="POST" action="<?php $_SERVER["PHP_SELF"] ?>">

<h1>Password recovery</h1>

<br>

Please provide username:

<br><br>

<input type="text" name="username">

<br><br>

Please provide email address:

<br><br>

<input type="text" name="email">

<br><br>

<input type="submit" value="Send">

</form>

</center>

 

Link to comment
Share on other sites

this should work:

 

<?php 

session_start();

$host="localhost"; // Host name
$username="root"; // Mysql username
$password="mypassword"; // Mysql password
$db_name="hunterli"; // Database name


//Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

if($_POST['submit']){
   
   $username=$_POST['username'];
   $email=$_POST['email'];
   
   $sql="SELECT * FROM tb_users WHERE username='$username' and email='$email'";
   $sql_result=mysql_query($sql)or die(mysql_error());
   
   while($x=mysql_fetch_assoc($sql_result)){
      
      if( ($x['username']) && ($x['email']) > 1){
      
         $new_pass=rand(0,123456);
         
         $_SESSION['pass']=$new_pass;
         
         $new_pass= md5($_SESSION['pass']);
         
         $sql2="UPDATE tb_users set password='$new_pass' WHERE username='$username' AND email='$email'";
         
         $sql2=mysql_query($sql2) or die(mysql_error());
         
         
                echo "


            
                 Your new ".$x['username']." password

                 
                 Username: ".$x['username']."


                 Password: ".$_SESSION['pass']."


                 
                 Please try to remember your new password cheers!


                                     or change your password in your members area to a
                                     easy remembered password";
         }else{
            
            echo" Sorry we have no record of your username or email


             please join our website


             <a href='login.php'>join now!<a>";
            exit;
         }
              }
               }
?>
<center>
<form method="POST" action="<?php $_SERVER["PHP_SELF"] ?>">
<h1>Password recovery</h1>


Please provide username:



<input type="text" name="username">



Please provide email address:



<input type="text" name="email">



<input type="submit" value="Send">
</form>
</center>

 

// I just edited it again, now try

Link to comment
Share on other sites

 

 

advance thank you the code currenly works fine updates database but the else dosent work

just dosent echo the message out well weried.....

 

 

 

<?php session_start();

//
//CREATE TABLE `database_test`.`pass` (
//`id` SMALLINT( 5 ) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY ,
//`username` VARCHAR( 25 ) NOT NULL ,
//`password` VARCHAR( 35 ) NOT NULL ,
//`email` VARCHAR( 50 ) NOT NULL
//) ENGINE = InnoDB 
//


$db=mysql_connect("xxx","xxxxx","xxxx");

$db_result=mysql_select_db("database_test",$db);


if($_POST['submit']){

$username=$_POST['username'];

$email=$_POST['email'];


if(empty($username)||(empty($email))){

	echo"<center> <font color='red'>Please fill in all the form!</font></center>";

		unset($_SESSIOM['pass']);  
}


$sql="SELECT * from pass where username='$username' AND email='$email' and id='00001'";
    
$sql_result=mysql_query($sql)or die(mysql_error());

while($x=mysql_fetch_assoc($sql_result)){


	if( ($x['email']) || ($x['username']) == 1){

	 $new_pass=rand(0,123456);

	   $_SESSION['pass']=$new_pass;

		$new_pass=(md5($_POST['new_pass']));

		$sql2="UPDATE pass set password='$new_pass' WHERE
		username='$username' AND email='$email' and id='00001'";

		$result2=mysql_query($sql2) or die(mysql_error());


		    	echo "<br><br>

			     Your new ".$x['username']." password <br><b><br><br>
			     
			     Username: ".$x['username']." <br><br>
			     Password: ".$_SESSION['pass']." <br><br>
			     
			     Please try to remember your new password cheers! <br><br>
                                     or change your password in your members area to a 
                                     easy remembered password";
		    	
		    		unset($_SESSIOM['pass']);  
		exit;


		  }else{



	echo" Sorry we have no record of your username: $username or email: $email <br><br>
			 please join our website <br><br>
                 <a href='join.php'>join now!<a>";

	unset($_SESSIOM['pass']); 

	exit;
}
		}

	}

?>
<center>
<form method="POST" action=" ">
<h1>Password recovery</h1>
<br>
Please provide username:
<br><br>
<input type="text" name="username">
<br><br>
Please provide email address:
<br><br>
<input type="text" name="email">
<br><br>
<input name="submit" type="submit" value="Send">
</form>
</center>

Link to comment
Share on other sites

why dosent the else work on this new rewritten code please..

 

i addaed the mysql_num_rows but the else dosent still work any idears plese...

 

<?php session_start();

//
//CREATE TABLE `database_test`.`pass` (
//`id` SMALLINT( 5 ) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY ,
//`username` VARCHAR( 25 ) NOT NULL ,
//`password` VARCHAR( 35 ) NOT NULL ,
//`email` VARCHAR( 50 ) NOT NULL
//) ENGINE = InnoDB 
//


$db=mysql_connect("xxx","xxx","xxxx");

$db_result=mysql_select_db("database_test",$db);

if($_POST['submit']){

$username=$_POST['username'];

$email=$_POST['email'];


if(empty($username)||(empty($email))){

	echo"<center> <font color='red'>Please fill in all the form!</font></center>";

  }


$sql="SELECT * from pass where username='$username' AND email='$email' and id='00001'";
    
$sql_result=mysql_query($sql)or die(mysql_error());

while($x=mysql_fetch_assoc($sql_result)){


	if(mysql_num_rows($sql_result)==1){

	 $new_pass=rand(0,123456);

	   $_SESSION['pass']=$new_pass;

		$new_pass=(md5($_POST['new_pass']));

		$sql2="UPDATE pass set password='$new_pass' WHERE
		username='$username' AND email='$email' and id='00001'";

		$result2=mysql_query($sql2) or die(mysql_error());


		    	echo "<br><br>

			     Your new ".$x['username']." password <br><b><br><br>
			     
			     Username: ".$x['username']." <br><br>
			     Password: ".$_SESSION['pass']." <br><br>
			     
			     Please try to remember your new password cheers! <br><br>
                                     or change your password in your members area to a 
                                     easy remembered password";
		    	
		    		unset($_SESSIOM['pass']);  
		exit;


		  }else{

	       echo" Sorry we have no record of your username: $username or email: $email <br><br>
			 please join our website <br><br>
                 <a href='join.php'>join now!<a>";

	exit;
}
		}

	}

?>
<center>
<form method="POST" action=" ">
<h1>Password recovery</h1>
<br>
Please provide username:
<br><br>
<input type="text" name="username">
<br><br>
Please provide email address:
<br><br>
<input type="text" name="email">
<br><br>
<input name="submit" type="submit" value="Send">
</form>
</center>

Link to comment
Share on other sites

why dosent the else work on this new rewritten code please..

 

i addaed the mysql_num_rows but the else dosent still work any idears plese...

 

<?php session_start();

//
//CREATE TABLE `database_test`.`pass` (
//`id` SMALLINT( 5 ) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY ,
//`username` VARCHAR( 25 ) NOT NULL ,
//`password` VARCHAR( 35 ) NOT NULL ,
//`email` VARCHAR( 50 ) NOT NULL
//) ENGINE = InnoDB 
//


$db=mysql_connect("xxx","xxx","xxxx");

$db_result=mysql_select_db("database_test",$db);

if($_POST['submit']){

$username=$_POST['username'];

$email=$_POST['email'];


if(empty($username)||(empty($email))){

	echo"<center> <font color='red'>Please fill in all the form!</font></center>";

  }


$sql="SELECT * from pass where username='$username' AND email='$email' and id='00001'";
    
$sql_result=mysql_query($sql)or die(mysql_error());

while($x=mysql_fetch_assoc($sql_result)){


	if(mysql_num_rows($sql_result)==1){

	 $new_pass=rand(0,123456);

	   $_SESSION['pass']=$new_pass;

		$new_pass=(md5($_POST['new_pass']));

		$sql2="UPDATE pass set password='$new_pass' WHERE
		username='$username' AND email='$email' and id='00001'";

		$result2=mysql_query($sql2) or die(mysql_error());


		    	echo "<br><br>

			     Your new ".$x['username']." password <br><b><br><br>
			     
			     Username: ".$x['username']." <br><br>
			     Password: ".$_SESSION['pass']." <br><br>
			     
			     Please try to remember your new password cheers! <br><br>
                                     or change your password in your members area to a 
                                     easy remembered password";
		    	
		    		unset($_SESSIOM['pass']);  
		exit;


		  }else{

	       echo" Sorry we have no record of your username: $username or email: $email <br><br>
			 please join our website <br><br>
                 <a href='join.php'>join now!<a>";

	exit;
}
		}

	}

?>
<center>
<form method="POST" action=" ">
<h1>Password recovery</h1>
<br>
Please provide username:
<br><br>
<input type="text" name="username">
<br><br>
Please provide email address:
<br><br>
<input type="text" name="email">
<br><br>
<input name="submit" type="submit" value="Send">
</form>
</center>

thank you , but this part still can not display :

echo" Sorry we have no record of your username: $username or email: $email <br><br>
			 please join our website <br><br>
                 <a href='join.php'>join now!<a>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.