Password checker in PHP I have written a password checker using PHP, consisting of many if else statements. Is there any possible way to shorten this code?

function passtest($pass) {
            if (!empty($pass)) { //check if string is empty
                if (ctype_alnum($pass)) { //check if string is alphanumeric
                    if (7 &lt; 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 "&lt;br /&gt;Password passed";
                                }
                                else {
                                    return "&lt;br /&gt;No capital letter";
                                }
                            }
                            else {
                                return "&lt;br /&gt;No small letter";
                            }
                        }
                        else {
                            return "&lt;br /&gt;No number";
                        }
                    }
                    else {
                        return "&lt;br /&gt;Password is short";
                    }
                }
                else {
                    return "&lt;br /&gt;Password has special character";
                }
            }
            else {
                return "&lt;br /&gt;Password field is empty";
            }
        }
I have an answer which also changes the logic of your code but I think there is a good reason why you should consider it:

function passtest($pass) {
    $errors = array();
    if (empty($pass)) $errors[] = 'Password field is empty';
    if (ctype_alnum($pass)) $errors[] = 'Password has special character';
    [...]

    return '&lt;br /&gt;' . implode('&lt;br&gt;', $errors);
}


Since it appears like this is somehow shown to the user I would notifyabout all  the errors that happened in choosing the password, so that they can all be corrected in a single try.

Another sidenote: Since your code reminds me of the time where I was just getting started and this seems to be at least somewhat related:
Don't save passwords, save their hashes. And use a good hashing implementation. If you're using PHP >= 5.5, there is a really easy way.

And thanks to "Fge", I can also give you a slightly less easy way for earlier PHP versions (>= 5.3.7).