Click to See Complete Forum and Search --> : [RESOLVED] Problem testing password length


tripodkid
03-18-2006, 11:49 AM
Hello,

I wrote this very simple script to test the length of passwords. However, it always redirects to the error header location even when the password is between 5 - 10 characters. When the password is not between 5 - 10 characters the script acts as it should and exits. But, when password is between 5 - 10 characters the script continues without exiting even though it redirects to the error header location.

This is driving me crazy and I know I must be missing something really dumb here!

Many thanks for your help!

Chris
//Checks that the password is between 5-10 characters
$password = ($_POST['customer_password']);
$pw_len = strlen($password);
if(($pw_len <5) || ($pw_len >10)){
header("Location:register.php?error=PWlen");
exit;
}

Mau
03-18-2006, 11:53 AM
Try printing out $pw_len to see what value it contains. Also, set your error reporting to E_ALL. Example:


error_reporting(E_ALL);

$password = ($_POST['customer_password']);
print $password;

$pw_len = strlen($password);
print $pw_len;

if(($pw_len <5) || ($pw_len >10)){
header("Location:register.php?error=PWlen");
exit;
}


See what you get. My bet is that $pw_len is 0 no matter what.

tripodkid
03-18-2006, 12:24 PM
I tried that and $pw_len does return the correct # of characters. I also printed $password and that matches the password entered in the form.

Mau
03-18-2006, 12:31 PM
Try something like this:

$password = '1234';
print $password . "\n";

$pw_len = strlen($password);
print $pw_len . "\n";

if($pw_len >= 5 && $pw_len <= 10)
{
print 'Good';
}
else
{
die('Bad');
}

Tested and working on PHP 5.1 via CLI.

NogDog
03-18-2006, 12:58 PM
Any possibility there's another place in the code you do a header("Location:register.php?error=PWlen");? perhaps you copied-and-pasted that line for a different error condition and forgot to change the value of "?error="?

tripodkid
03-18-2006, 01:39 PM
Thanks for your help!

I've found the problem. It's where a second header is pointing, 100 lines later in the script!

Chris