Jump to content

Change Password Form


kevin_it

Recommended Posts

I have built a php page that will allow a user to change their password and it works great. What I would like to accomplish now is to compare the "New Password" field (newpassword) and the "Confirm Password" field (confpass) to make sure they are both the same.

What would be the commands to do this. I am a "just climbed out of the n00b status".

:)

Thanks everyone.

Kevin
Link to comment
Share on other sites

Billy bob is right. I personaly don't like placeing my sucess code before the error code. So I do this

[code=php:0]
if ($newpass !== $confpass) {
    echo "Your passwords do not match";
    include("yourform.php");
    exit;
}
/*Now you can place your success code below here and wont have to worry about
closing the } or rembering to put in your error code at the end of the file. */
[/code]
Link to comment
Share on other sites

I guess that it would be a personal choice. Well also it is a lot cleaner looking and is a little easier to trouble shoot. For instance ,if you do it the way BillyBob suggested, say you have some more if statements it would realy be easy to forget a } along the line.

Here is a simple example, say in the eample that you are also going to check to make sure the user is logged in.

[code=php:0]
session_start();
if (!$_SESSION['username']) {
    echo "Your session error message";
}else{
    if($newpass==$confpass){
      $sql = "";//a sql query to update passwords.
      if (!$sql) {
          echo "a error message";
      }//it would be realy easy to forget one of these somewhere along the lines
      //some more code here
    }else{
      echo("Your passwords don't match!");
    }
}[/code]

Where as if you do it the way that I do it would look like this.

[code=php:0]
if (!$_SESSION['username']) {
    echo "Your error message";
    include("your_login.php");
    exit;
}
if ($newpass !== $confpass) {
    echo "Your passwords do not match";
    include("yourform.php");
    exit;
}
$sql = "";//a sql query to update passwords

if (!sql) {
  echo "Your sql error message";
}
//somemore code here
[/code]

As you can see this is the samething but with one major difference. The layout is alot easier to trouble shoot any problems.

Tom 
Link to comment
Share on other sites

Just done this for you hope it helps good luck.

recover password via email.


[code]
<?phpsession_start();

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


if(!$email=="none"){

echo "<html><body vlink='black' alink='black' link='black'><br><br><br><table

bordercolor='black'border='4' align='center'><td align='center'><h1><font color='red'>whatever!

</font> <h1>valadation Warning!</h1></td></table><br><br><br><div align='center'><font

color='red'><b>Sorry please fill in all the form.</b></font> <br> <br> <a

href='lostpassword.php'>
<b>Please try agin!</b> </a><br><br><br><br><br><br><br><br><br><br><br><br><br><hr

color='black'><font color='red'>((c))Admin@whatever.com --whatever! --</font><hr

color='black'></hr></body></html></div>";
exit;

}

$password=($_POST['password']);
$email=($_POST['email']);

$query="select * from members where email='$email'";
$result=mysql_query($query);

if(!mysql_num_rows($result)) {

echo "<html><body vlink='black' alink='black' link='black'><br><br><br><table

bordercolor='black'border='4' align='center'><td align='center'><h1><font color='red'>Blob it!

</font> <h1>valadation Warning!</h1></td></table><br><br><br><div align='center'><font

color='red'><b>Sorry there no account for the email address $email!.</b></font> <br> <br> <a

href='lostpassword.php'>
<b>Please try agin!</b> </a><br><br><br><br><br><br><br><br><br><br><br><br><br><hr

color='black'><font color='red'>((c))Admin@whay ever.com --whatever! --</font><hr

color='black'></hr></body></html></div>";
exit;

}else{

while($record=mysql_fetch_assoc($result)){


$pass=$_SESSION['pass']=$record['password'];


$to = $email;
$subject = 'Password recovery!';
$message = "

<html><body vlink='black' alink='black' link='black'><br><br><br><table

bordercolor='black'border='4' align='center'><td align='center'><h1><font color='red'>Blob it!

</font> <h1>Password recovery notice!</h1></td></table><br><br><br><div align='center'><font

color='red'><b><h3>Your password is: $pass<br>Please use the link below to login thank

you.</b></font> <br> <br></h3> <a

href='http://xxxxxxxx.com/login.php'>Login know!</a>
</a><br><br><br><br><br><br><br><br><br><br><br><br><br><hr color='black'><font

color='red'>((c))Admin@whatever.com --website name! --</font><hr

color='black'></hr></body></html></div>";



$headers = "From: Do not email back\r\n" .
       'X-Mailer: PHP/' . phpversion() . "\r\n" .
       "MIME-Version: 1.0\r\n" .
       "Content-Type: text/html; charset=utf-8\r\n" .
       "Content-Transfer-Encoding: 8bit\r\n\r\n";


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


echo "<html><body vlink='black' alink='black' link='black'><br><br><br><table

bordercolor='black'border='4' align='center'><td align='center'><h1><font color='red'>Blob it!

</font></h1> <h1>Password recovery</h1> <a

href='see.php'>Home</a></td></table><br><br><br><div align='center'><font

color='red'><b>Please goto your email account and get your password!</b></font> <br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><hr color='black'><font

color='red'>((c))Admin@whatever.com --whatever.com  --</font><hr

color='black'></hr></body></html></div>";
exit;

}
}

?>
[/code]
Link to comment
Share on other sites

Thank you very much everyone. I really appreciate it. Like I said, I have tore off my n00b skin and am getting better with PHP. Still a lot to learn, but with great healp like this I can keep myself on the right track.

Thank again all!!

A+++++++

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