MySQL password verification

My problem:

I have a password check that ensures that the password will not be> 25 or 5 characters before it is inserted into the database. If so, he spits out an error. Everything works fine, but I can’t get it to check if the password is <5 and> 25 characters, and then put it in the database.

Code Section:

if (strlen($pswd)>30) { echo "Your password is too long! Password should be between 5 and 30 characters long!"; } if (strlen($pswd)<5) { echo "Your password is too short! Password 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 ..."); } 
+4
source share
1 answer

Try combining all if statuses into one if-elseif-else:

 if (strlen($pswd)>30) { echo "Your password is too long! Password should be between 5 and 30 characters long!"; } else if (strlen($pswd)<5) { echo "Your password is too short! Password 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 ..."); } 
+4
source

All Articles