Skip to main content
edited tags
Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Tweeted twitter.com/#!/StackCodeReview/status/437265729092866049
deleted 5 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

PHP password Password checker in PHP

I have written a password checker using PHP and it consists, consisting of many "if else"if else statements. Is there any possible way to shorten this codescode?

PHP password checker

I have written a password checker using PHP and it consists of many "if else" statements. Is there any possible way to shorten this codes?

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?

Source Link
user3326060
  • 101
  • 1
  • 1
  • 5

PHP password checker

I have written a password checker using PHP and it consists of many "if else" statements. Is there any possible way to shorten this codes?

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";
            }
        }