Skip to content

Instantly share code, notes, and snippets.

@memoryleak
Created July 7, 2020 12:51
Show Gist options
  • Save memoryleak/63ffaab008dfc4225b27f34bfb12f83e to your computer and use it in GitHub Desktop.
Save memoryleak/63ffaab008dfc4225b27f34bfb12f83e to your computer and use it in GitHub Desktop.
import re
_HASH_RE = re.compile(r'[^a-zA-Z0-9./=]')
fields = "$6$7XhBc13.5MtmI1MQ$l4hdVQnszutOZxKYU/Ih5i9w9eFAIwMK4Nu9nDLrSTaD.p6eHhMgD.2C2s/PZhqTdqv8mk1/MDhHyWSW/HFly0".split("$")
maybe_invalid = False
if len(fields) >= 3:
# contains character outside the crypto constraint
if bool(_HASH_RE.search(fields[-1])):
maybe_invalid = True
# md5
if fields[1] == '1' and len(fields[-1]) != 22:
maybe_invalid = True
# sha256
if fields[1] == '5' and len(fields[-1]) != 43:
maybe_invalid = True
# sha512
if fields[1] == '6' and len(fields[-1]) != 86:
maybe_invalid = True
else:
maybe_invalid = True
if maybe_invalid:
print("The input password appears not to have been hashed. "
"The 'password' argument must be encrypted for this module to work properly.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment