Testing the Complexity of Passwords
<?php
$values = array(
"password", // Bad
"P4ssw0rd", // Good
);
foreach ($values as $value) {
if (! preg_match( '/^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{8,16}/', $value)) {
printf("Bad password: '%s'\n", $value);
} else {
printf("Good password: '%s'!\n", $value);
}
}
?>
Related examples in the same category