Jump to content


Photo

Change Password Form


  • Please log in to reply
9 replies to this topic

#1 kevin_it

kevin_it
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 August 2006 - 08:17 PM

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

#2 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 02 August 2006 - 09:02 PM

ok well the answer would be ...

make a form with both new pass old pass and confpass

then use this if statment

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


#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 02 August 2006 - 09:39 PM

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

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. */

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 02 August 2006 - 10:26 PM

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
Tell me the problem, I will try tell you the solution

#5 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 03 August 2006 - 03:12 AM

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.

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!");
    }
}

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

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

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

Tom 

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#6 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 03:17 AM

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{
}

Tell me the problem, I will try tell you the solution

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 August 2006 - 03:26 AM

Just done this for you hope it helps good luck.

recover password via email.


<?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;

}
 }

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 kevin_it

kevin_it
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 03 August 2006 - 11:35 AM

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

#9 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 12:09 PM

You are always learning
WHen you stop learning, thats when it becomes boring
Tell me the problem, I will try tell you the solution

#10 Liquid Fire

Liquid Fire
  • Members
  • PipPipPip
  • Advanced Member
  • 806 posts

Posted 04 August 2006 - 01:59 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users