*fixed email - problem with password

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
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

*fixed email - problem with password

Post by ol4pr0 »

problem with email was i had 2 field names with email. so if one didnt had a value.. the error was returned dumb lol.

However i have this problem. (might be that i am stairing at it to long )

When i start up the page..
i get this error

Notice: Undefined variable: password_confirm_emtpy in on line 318
When both passwords field is blank and i do a submit i get this error
Notice: Undefined index: password_confirm in on line 49
Notice: Undefined index: password_confirm in on line 314
When only the first or the second password left blank all erros are gone

Code: Select all

//part that check if password is 0 and if password is same as the second password 

if(strlen($_POST['password'])>0)
	{
	$password = '1';
	}
	else
	{
	$password_empty ='<font style="color: '.$tcolour.'; font-size:'.$tfontsize.'px;">* Enter a password</font>';
	}
                // line 50
	if ($_POST['password'] == $_POST['password_confirm'])
	{
	$password_confirm = '1';
	}
	else
	{
	$password_confirm_emtpy ='<font style="color: '.$tcolour.'; font-size:'.$tfontsize.'px;">* you''re password must match</font>';
	}

Code: Select all

if($password_confirm == '1')
	{
                //line 314
	echo '<td class="row1"><span class="gen">Confirm password: * </span><br /><span class="gensmall"></span></td><td class="row2"><input type="password" class="post" style="width: 200px" name="password_confirm" size="25" maxlength="32" value="'.$_POST['password_confirm'].'" /></td>';
	}
	elseif($password_confirm != '1')
	{
	echo '<td class="row1"><span class="gen">Confirm password: * </span><br /><span class="gensmall"></span></td><td class="row2"><input type="password" class="post" style="width: 200px" name="password_check" size="25" maxlength="32" value="" />'.$password_confirm_emtpy.'</td>';
	}
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Any help appriciated
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

switch:

if ($_POST['password'] == $_POST['password_confirm'])

to

if (!empty($_POST['password']) && !empty($_POST['password_confirm']) && $_POST['password'] == $_POST['password_confirm'])

-----

your logic is kinda screwy... additionally, it's a really bad idea to write out the user's password:

Code: Select all

if($password_confirm == '1') 
   { 
                //line 314 
   echo '<td class="row1"><span class="gen">Confirm password: * </span><br /><span class="gensmall"></span></td><td class="row2"><input type="password" class="post" style="width: 200px" name="password_confirm" size="25" maxlength="32" value="'.$_POST['password_confirm'].'" /></td>'; 
   }
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

That still leaves me with this problem
Notice: Undefined variable: password_confirm_emtpy in on line 318
while it has been declared as far as i can see,

And if the logic is kinda screwy how would you check the second password against the first password.

Code: Select all

if (!empty($_POST['password']) && !empty($_POST['password_confirm']) && $_POST['password'] == $_POST['password_confirm']) 
	{
	$password_confirm = '1';
	}
	else
	{
	$password_confirm_emtpy ='<font style="color: '.$tcolour.'; font-size:'.$tfontsize.'px;">* you''re password must match</font>';
	} 

//line 318
echo '<td class="row1"><span class="gen">Confirm password: * </span><br /><span class="gensmall"></span></td><td class="row2"><input type="password" class="post" style="width: 200px" name="password_confirm" size="25" maxlength="32" value="" />'.$password_confirm_emtpy.'</td>'; 
   }
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

fixed it i guess by changing

Code: Select all

$password_confirm_empty 

//into

$password_confirm
however since the logic is kinda.. as you said i would still like to know how you would handle this. Unless that comment has something do to do with the returning the value
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$error = '';
// you may want a regex to confirm syntax and correct length of the password...
if(!empty($_POST['password']) && !empty($_POST['password_confirm']) && $_POST['password'] === $_POST['password_confirm'])
{
  // yay, they match! do your insert and redirect or whatever...
}
else
{
  if(empty($_POST['password']))
  {
    $error .= (!empty($error)?'<br />':'').'&#149; must enter a password';
  }

  if(empty($_POST['password_confirm']))
  {
    $error .= (!empty($error)?'<br />':'').'&#149; must confirm password';
  }

  if(!empty($_POST['password']) && !empty($_POST['password_confirm']) && $_POST['password'] !== $_POST['password_confirm'])
  {
    $error .= (!empty($error)?'<br />':'').'&#149; passwords did not match';
  }

  die((!empty($error)?$error:'uncaught error, oops.'));
}
Post Reply