Created
November 23, 2018 17:40
-
-
Save earth3300/8eda6f140fceebe21695bc773be0a85b to your computer and use it in GitHub Desktop.
Password validation using regex.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Password Validation | |
| * | |
| * @link https://stackoverflow.com/a/21456918/5449906 | |
| * | |
| * @param $string | |
| * | |
| * @return bool | |
| */ | |
| private function validatePassword( $password ) | |
| { | |
| if ( false ) { | |
| /** Minimum eight characters, at least one letter and one number: */ | |
| $regex = "/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}/"; | |
| /** Minimum eight characters, at least one letter, one number and one special character: */ | |
| $regex = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/"; | |
| /** Minimum eight characters, at least one uppercase letter, one lowercase letter and one number: */ | |
| $regex = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/"; | |
| /** Minimum eight and maximum 10 characters, at least one uppercase letter, one lowercase letter, one number and one special character: */ | |
| $regex = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,10}$/"; | |
| } | |
| else | |
| { | |
| return false; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Non-functional.