Skip to content

Instantly share code, notes, and snippets.

@rapPayne
Created October 21, 2020 21:44
Show Gist options
  • Select an option

  • Save rapPayne/54c96a556e94915812c265cbc03ed8f2 to your computer and use it in GitHub Desktop.

Select an option

Save rapPayne/54c96a556e94915812c265cbc03ed8f2 to your computer and use it in GitHub Desktop.
Creating the _validatePassword method
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