I have written a password checker using PHP and It worked fine. It consists of many "if else". Is there any way to minimize my usage of "if else" in my code?
function passtest($pass) {
if (!empty($pass)) { //check if string is empty
if (ctype_alnum($pass)) { //check if string is alphanumeric
if (7 < strlen($pass)){ //check if string meets 8 or more characters
if (strcspn($pass, '0123456789') != strlen($pass)){ //check if string has numbers
if (strcspn($pass, 'abcdefghijklmnopqrstuvwxyz') != strlen($pass)) { //check if string has small letters
if (strcspn($pass, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') != strlen($pass)) { //check if string has capital letters
return "<br />Password passed";
}
else {
return "<br />No capital letter";
}
}
else {
return "<br />No small letter";
}
}
else {
return "<br />No number";
}
}
else {
return "<br />Password is short";
}
}
else {
return "<br />Password has special character";
}
}
else {
return "<br />Password field is empty";
}
}