Created
October 21, 2020 21:44
-
-
Save rapPayne/54c96a556e94915812c265cbc03ed8f2 to your computer and use it in GitHub Desktop.
Creating the _validatePassword method
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
| String _validatePassword(String pass1) { | |
| // 1 | |
| RegExp hasUpper = RegExp(r'[A-Z]'); | |
| RegExp hasLower = RegExp(r'[a-z]'); | |
| RegExp hasDigit = RegExp(r'\d'); | |
| RegExp hasPunct = RegExp(r'[!@#\$&*~-]'); | |
| // 2 | |
| if (!RegExp(r'.{8,}').hasMatch(pass1)) | |
| return 'Passwords must have at least 8 characters'; | |
| // 3 | |
| if (!hasUpper.hasMatch(pass1)) | |
| return 'Passwords must have at least one uppercase character'; | |
| // 4 | |
| if (!hasLower.hasMatch(pass1)) | |
| return 'Passwords must have at least one lowercase character'; | |
| // 5 | |
| if (!hasDigit.hasMatch(pass1)) | |
| return 'Passwords must have at least one number'; | |
| // 6 | |
| if (!hasPunct.hasMatch(pass1)) | |
| return 'Passwords need at least one special character like !@#\$&*~-'; | |
| // 7 | |
| return null; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment