You should validate your passwords by ensuring they are secure, not that they're insecure.
public function password_is_secure($password) {
// quick obvious test
if (is_numeric($password)) {
// FAIL: 'Your password cannot be all numbers.'
} elseif (strlen(count_chars($password, 3)) < 4) {
// FAIL: 'Your password needs to have a variety of different characters.'
}
// levenshtein distance test (test similarity to common passwords)
$name = $_POST['name'];
$email = $_POST['email'];
$badPasswords = array($name, $email, 'password', 'password1', 'password123', '1234abcd', 'abcd1234', '12345678', '1234567890');
foreach($badPasswords as $bad) {
if (levenshtein($password, $bad) < 6) {
// FAIL: 'Your password is too similar to your name or email address or other common passwords.'
}
}
return true;
}
Plug-in more appropriate "getters" for $name
and $email
and setup how you want to handle passing error messages, and the above method will do you some justice. You can "tune" it by altering the allowed Levenschtein distance (currently 6).
I would also recommend extending the list of $badPasswords
to include a bunch of the most common passwords.
And for the love of some deity, salt and hash your passwords before you store them in the database.