changing password problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

changing password problem

Post by irealms »

in my script i have the following

if (strlen($new_passwd)>16 || strlen($new_passwd)<4)
{
echo "<div class=\"log\">Passwords must be between<br />4 and 16 chars.";
}
else
{
if ($_SESSION['pass'] != $old_passwd)
echo "<div class=\"log\">Your old password is incorrect<br />please try again.</div>";
if ($new_passwd!=$new_passwd2)
echo "<div class=\"log\">The passwords do not match.<br />passwords not changed.</div>";
}
how do i create a statement that will only execute if non of the above are true, ie. form was filled in correctly?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

if (strlen($new_passwd)>16 || strlen($new_passwd)<4)
	echo "<div class="log">Passwords must be between<br />4 and 16 chars.";
elseif ($_SESSION['pass'] != $old_passwd)
	echo "<div class="log">Your old password is incorrect<br />please try again.</div>";
elseif ($new_passwd!=$new_passwd2)
	echo "<div class="log">The passwords do not match.<br />passwords not changed.</div>";
else
{ // none of the above conditions matched
	
}
you might use else if instead of elseif as well
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Mostly i'm doing this with a temp error value.

Code: Select all

unset($error);
if(strlen($_POST&#1111;"new_passwd"]>16 || $_POST&#1111;"new_passwd"])
  $error = "Passwords must be between<br /> 4 and 16 chars.<br />";

if($_SESSION&#1111;'pass'] != $_POST&#1111;"old_passwd"])
  $error.= "Your old password is incorrect<br />please try again.<br />";

if ($_POST&#1111;"new_passwd"]!=$_POST&#1111;"new_passwd2"])&#123;
  $error.= "The passwords do not match.<br />passwords not changed.<br />";

if(isset($error))&#123;
  echo "<div class="log">".$error."</div>";
&#125;else&#123;
  // update statement. here  
&#125;
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

thanks

Post by irealms »

thanks for the help, it's working now

only problem i have now is that it only lets you change the password once unless you log out and in again
Post Reply