Jump to content

Archived

This topic is now archived and is closed to further replies.

kevin_it

Change Password Form

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

Share this post


Link to post
Share on other sites
ok well the answer would be ...

make a form with both new pass old pass and confpass

then use this if statment

[code]
if($newpass==$confpass)
{
//success whatever u do here
}else{
echo("Your passwords don't match!");
}
[/code]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
Is there any good reason behind making errors first, or just personal choice

I personally like having the main code in the middle, then the errors down the bottom, cutting off one by one

Share this post


Link to post
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 

Share this post


Link to post
Share on other sites
I think as long as you go one way, Errors inside or out, its ok
Some scripts I seen are all other the place

if(this is good){
if(this is wrong){
}else{
}
}else{
}

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
You are always learning
WHen you stop learning, thats when it becomes boring

Share this post


Link to post
Share on other sites
if you want to get real fancy you can try to use AJAX. with AJAX i am pretty sure you can have it so that they can't sumbit untill the passwrod match or at least have soem red text the will go away ro green when the password matched or something like that.

Share this post


Link to post
Share on other sites

×

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.