Forum Moderators: coopster

Message Too Old, No Replies

Password field validation

strange "passwords don't match error message"

         

dbarasuk

4:24 pm on Apr 13, 2008 (gmt 0)

10+ Year Member



Hey,
Can you spot wht's the error here?

I have a form collecting user data for registration.
the password field and another field to confirm the value typed in by user are defined as follows:

$pwd = strip_tags(trim($_POST['pwd'])); // password typed in
$conf_pwd = strip_tags(trim($_POST['conf_pwd'])); // same password to confirm the password

// checking both fields:

if(strlen($pwd) < 6) {
$message[] = "Password must be at least 6 characters .";
if($pwd != $conf_pwd)
{
$message[]="Your password don't match";
}
If I type in both fields for example "Helloworld" in the same case sensitive manner, I keep getting:
"Password must be at least 6 characters"
"Your passwords don't match"

This is strange since the two passwords are exactly the same.

I tried with something different to see if I can find a match of the two like this:
if(strlen($pwd) != strlen($conf_pwd)) {
$message[] = "Your passwords don't match.";} // this is of course to check because there would be a match with two different paswwords with same length.

This gives the second error message also.

I tried also:
if(!preg_match($pwd,$conf_pwd))
{
$message[]="Your passwords don't match,";
}
and the error is always the same: "Your password don't match".

It's running me crazy and I don't know what to do further.

Any help please,
Yours

Habtom

4:37 pm on Apr 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$pwd = strip_tags(trim($_POST['pwd'])); // password typed in
$conf_pwd = strip_tags(trim($_POST['conf_pwd']));

Check if the values are really passed, or what is exactly being compared.

$pwd = strip_tags(trim($_POST['pwd'])); // password typed in
$conf_pwd = strip_tags(trim($_POST['conf_pwd']));
echo "Password". $pwd ."<br>";
echo "Confirm Password". $conf_pwd ."<br>";

dbarasuk

12:12 am on Apr 14, 2008 (gmt 0)

10+ Year Member



I even printed the whole $_POST array like

echo "<pre>";
print_r($_POST);
echo "</pre>";

If i typed "Helloworld" in both fields I get back the SAME "Helloworld" in the printed array.

Can you suggest a solution?

thks