Skip to content

Instantly share code, notes, and snippets.

@jorgeas80
Created February 17, 2015 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgeas80/e2dfa5d942bfca5fef22 to your computer and use it in GitHub Desktop.
Save jorgeas80/e2dfa5d942bfca5fef22 to your computer and use it in GitHub Desktop.
Python function to validate a password string
import re
# Taking from https://gist.github.com/psjinx/5722079#file-utils-py
MINIMUM_PASSWORD_LENGTH = 8
REGEX_VALID_PASSWORD = (
## Don't allow any spaces, e.g. '\t', '\n' or whitespace etc.
r'^(?!.*[\s])'
## Check for a digit
'((?=.*[\d])'
## Check for an uppercase letter
'(?=.*[A-Z])'
## check for special characters. Something which is not word, digit or
## space will be treated as special character
'(?=.*[^\w\d\s])).'
## Minimum 8 characters
'{' + str(MINIMUM_PASSWORD_LENGTH) + ',}$')
def validate_password(password):
if re.match(REGEX_VALID_PASSWORD, password):
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment