Forum Moderators: coopster

Message Too Old, No Replies

Registering client - 1 small problem on pw length check

         

Orangutang

1:05 pm on Jul 14, 2010 (gmt 0)

10+ Year Member



Hi,

I'm developing my registration script and have one problem on my checks. All checks work ok except the code doesn't check the password length correctly, It allows registration if the pw is less than 6 chars when it should only allow registration if the pws are greater than 6 but less than 16.

The code reads: if ((strlen($password) < 6) || (strlen($password) > 16)) // This should work to me, if strlen less than 6 or strlen greater than 16 but I've obviuosly made a mistake.

Please find the code below:

<?php
if ($email && $username && $password && $password2) // AAA - If fields filled out on form. OK
{
if ($password == $password2) // BBB - If entered passwords match on form. OK
{
if (strstr($email, "@")&& strstr($email, ".")) // CCC - If email has @ sign and a dot on form. OK
{
if ((strlen($password) < 6) || (strlen($password) > 16)) // DDD - DOES NOT WORK PROPERLY - Less than 6 granted.
{
$sqlCommand = "INSERT INTO clients (email, username, password)
VALUES('$email','$username','$password')";

$query = mysql_query($sqlCommand) or die (mysql_error());
$clientid = mysql_insert_id();

echo "<b>You have been registered. Your clientid is: </b>" . $clientid;
mysql_close();
}
else
echo "Your password must be between 6 and 16 characters, please go back and try again."; // DDD
}
else
echo "No @ sign or dot in email address."; // CCC
}
else
echo "Passwords did not match"; // BBB
}
else
echo "Please fill out the registration form correctly. None or only part of the details were supplied."; // AAA
?>

Any help would be really useful because for the life of me I cannot understand why this code will not work correctly.

Many thanks

Matthew1980

2:17 pm on Jul 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there orangutang,
if ((strlen($password) < 6) || (strlen($password) > 16))

try:-
if ((strlen($password) <= 6) || (strlen($password) >= 16))


If you are comparing, you need to say less than equal to, || more than equal to - at least in this context I think as this would do the trick :)

Cheers,
MRb

Orangutang

3:02 pm on Jul 14, 2010 (gmt 0)

10+ Year Member



Hi Matthew,

How strange is that, your advice makes perfect sense,less than equal to || more than equal to.

I added the = signs but unfortunately still registers wrong way round.

Very strange but thanks anway