For my rule here I want to validate a password field that contains at least 5 characters long but those must not be abcde or 12345 or reverse. How can I? Here I don't want to force users to enter at least 1 letter 1 number or a symbols in combination.
Asked
Active
Viewed 405 times
-5
-
3show us what you have tried – donald123 Jul 03 '15 at 07:02
-
1Why does it have to be done using regex? You can check for known bad values in PHP code. – anubhava Jul 03 '15 at 07:02
-
Have you already tried something? Because that looks to me like something that is easy to solve? Anyway, if it isn't, give us some code about your previous attempts and why you didn't like the results of your code. So it's easier for us to give you feedback on your own code. – ndsmyter Jul 03 '15 at 07:03
-
Here I didn't mean only 12345, but 123456789 or abcde, but abcdefg something like this – Daroath Jul 03 '15 at 10:18
-
Just make a dictionary with the most common passwords, and test against this dictionary. There are not so many realistic combinations with 123 1234 12345 to test. With a dictionary you can also test combinations like `qwert` or `password`. – martinstoeckli Jul 03 '15 at 10:56
1 Answers
1
$uppercase = preg_match('@[A-Z]@', $password);
$lowercase = preg_match('@[a-z]@', $password);
$number = preg_match('@[0-9]@', $password);
if(!$uppercase || !$lowercase || !$number || strlen($password) < 8) {
// tell the user something went wrong
}
documentation: http://php.net/manual/de/function.preg-match.php
source: Regex for password PHP

Community
- 1
- 1