Form and Spelling Validation -
(Page 7 of 14 )
In our password strength function, we will require that a password pass three different validations. First, it must meet a specific length. In our case, we are requiring that a password is at least eight characters. Then, we check to be sure that we have a fair amount of unique characters being used. A password that uses the same few characters repeatedly is not secure. Finally, we validate that there are a combination of numbers and letters and that at least one number has a letter on either side of it.
<?php function checkPassword($password) { $length = strlen ($password); if ($length < 8) { return FALSE; } $unique = strlen (count_chars ($password, 3)); $difference = $unique / $length; echo $difference; if ($difference < .60) { return FALSE; } return preg_match ("/[A-z]+[0-9]+[A-z]+/", $password); } ?> |
Next: >>
More Miscellaneous Articles
More By Matt Wade