Charon
Charon

Reputation: 95

MySQL password checker

My issue:

I have a password checker that makes sure the password isn't >25 or <5 chars before it's inserted into the database. If it is, it spits out an error. That all works perfectly, however I cannot seem to get it to check if the password is not <5 and or >25 chars and then put it into the database.

The section of code:

if (strlen($pswd)>30) {
echo "Your password is too long! Password's should be between 5 and 30 characters long!";
}

if (strlen($pswd)<5) {
echo "Your password is too short! Password's should be between 5 and 30 characters long!";
}

else if (!strlen($pswd)>30||strlen($pswd)<5)
{
$query = mysql_query("INSERT INTO users VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0')");
die("<h2>Welcome to M8Ster</h2>Please login to your account to get started ...");
}

Upvotes: 4

Views: 211

Answers (1)

drew010
drew010

Reputation: 69967

Try combining all the if statments into one if-elseif-else:

if (strlen($pswd)>30) {
    echo "Your password is too long! Password's should be between 5 and 30 characters long!";
} else if (strlen($pswd)<5) {
    echo "Your password is too short! Password's should be between 5 and 30 characters long!";
} else {
    $query = mysql_query("INSERT INTO users VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0')");
    die("<h2>Welcome to M8Ster</h2>Please login to your account to get started ...");
}

Upvotes: 4

Related Questions