Jump to content

password change code


johnnyblaze9

Recommended Posts

Can someone tell  me what I have wrong in this password change code?

 

I have these on 2 different pages...might that be the problem?

 

 

//passwordchange.php is first

 

 

<?php

 

 

 

echo "<form action='passwordchk.php' method=post><input type=hidden name=todo value=change-password>

 

<table border='0' cellspacing='0' cellpadding='0' align=center>

<tr bgcolor='#f1f1f1' > <td colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'> <b>Change  Password</b> </font></td> </tr>

 

<tr bgcolor='#ffffff' > <td ><font face='verdana, arial, helvetica' size='2' align='center'>   New Password 

</font></td> <td  align='center'><font face='verdana, arial, helvetica' size='2' >

<input type ='password' class='bginput' name='password' ></font></td></tr>

 

<tr bgcolor='#f1f1f1' > <td ><font face='verdana, arial, helvetica' size='2' align='center'>   Re-enter New Password 

</font></td> <td  align='center'><font face='verdana, arial, helvetica' size='2' >

<input type ='password' class='bginput' name='password2' ></font></td></tr>

 

<tr bgcolor='#ffffff' > <td colspan=2 align=center><input type=submit value='Change Password'><input type=reset value=Reset></font></td></tr>

 

";

 

 

echo "</table>";

 

echo "<center><font face='Verdana' size='2' ><br>Click <a href=logout.php>here to logout for better security</font></center>";

?>

 

 

//passwordchk.php is below

 

 

<?

if(isset($todo) and $todo=="change-password"){

$password=mysql_real_escape_string($password);

 

 

$status = "OK";

$msg="";

 

 

 

 

if ( strlen($password) < 3 or strlen($password) > 8 ){

$msg=$msg."Password must be more than 3 char legth and maximum 8 char lenght<BR>";

$status= "NOTOK";}

 

if ( $password <> $password2 ){

$msg=$msg."Both passwords are not matching<BR>";

$status= "NOTOK";}

 

 

 

if($status<>"OK"){

echo "<font face='Verdana' size='2' color=red>$msg</font><br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";

}else{

if(mysql_query("update Contact set Password='$password' where ContactID='$session[ContactID]'")){

echo "<font face='Verdana' size='2' ><center>Thanks <br> Your password changed successfully. Please keep changing your password for better security</font></center>";

}

}

}

echo "<center><font face='Verdana' size='2' ><br><br>Click <a href=logout.php>here to logout</a>   |   <a href=change-password.php>Change Password</a><br></center></font>";

 

?>

Link to comment
https://forums.phpfreaks.com/topic/104546-password-change-code/
Share on other sites

Replace '<>' with '!='

 

Also, create a name for your submit button and do this:

 

<?php

if(isset($_POST['SUBMIT_NAME']){

$password=mysql_real_escape_string($password);
$status = "OK";
$msg="";

if ( strlen($password) < 3 or strlen($password) > 8 ){
$msg=$msg."Password must be more than 3 char legth and maximum 8 char lenght<BR>";
$status= "NOTOK";}               

if ( $password != $password2 ){
$msg=$msg."Both passwords are not matching<BR>";
$status= "NOTOK";}               



if($status!="OK"){
echo "<font face='Verdana' size='2' color=red>$msg</font>
<center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
}else{
if(mysql_query("update Contact set Password='$password' where ContactID='$session[ContactID]'")){
echo "<font face='Verdana' size='2' ><center>Thanks
Your password changed successfully. Please keep changing your password for better security</font></center>";
}
}
}
echo "<center><font face='Verdana' size='2' >

Click <a href=logout.php>here to logout</a>   |   <a href=change-password.php>Change Password</a>
</center></font>";

?>

Link to comment
https://forums.phpfreaks.com/topic/104546-password-change-code/#findComment-535150
Share on other sites

Archived

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

×
×
  • 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.