示例#1
0
        } else {
            if ($ch >= "A" && $ch <= "Z") {
                $letter_upper++;
            } else {
                if ($ch >= "0" && $ch <= "9") {
                    $numeric++;
                } else {
                    $non_alph++;
                }
            }
        }
    }
    // debug
    //echo "Lowercase letters: " . $letter_lower . "<br>";
    //echo "Uppercase letters: " . $letter_upper . "<br>";
    //echo "Numeric: " . $numeric . "<br>";
    //echo "Non-alphanumeric: " . $non_alph . "<br>";
    if (strlen($password) > 8 && $letter_lower > 0 && $letter_upper > 0 && $numeric > 1 && $non_alph > 0) {
        return 3;
        // strong
    } else {
        if (strlen($password) >= 6 && $letter_lower > 0 && $letter_upper > 0 && $numeric > 0) {
            return 2;
            // medium
        }
    }
    return 1;
    // weak
}
echo strength("abcadG3");
示例#2
0
<?php

/**
 * PHP basics Exercise #3
 */
function strength($password)
{
    // TODO this is for you to complete
    return 0;
}
echo strength("abc");
// 1: weak